Giter Site home page Giter Site logo

file-actions.yazi's Introduction

file-actions.yazi

a file action script plugin for Yazi that allows users to pass selected files into action scripts to perform corresponding actions on the files.

Note

The latest main branch of Yazi is required at the moment.

Installation

On Linux and Mac, install file-actions.yazi using the following command:

git clone https://github.com/BBOOXX/file-actions.yazi.git ~/.config/yazi/plugins/file-actions.yazi

For Termux users, you need to install file first:

pkg install file

Configuration

# keymap.toml
[[manager.prepend_keymap]]
on = [ "f" ]
exec = "plugin file-actions --args='around '"
desc= "Perform actions on selected files"

Or in another different style:

# keymap.toml
[manager]
prepend_keymap = [
# ...
	{ on = [ "f" ], exec = "plugin file-actions --args='around '", desc= "Perform actions on selected files"},
# ...
]

Action Script Setup

To set up an action script, create a new folder within the actions directory, ensuring it contains both init.lua and info.lua files.

info.lua

The info.lua file describes the action script. Here’s the basic format:

local config = {
	name = "Script Name",   -- Name of the script
	enableMimes = {},       -- Supported file mimes by the script
	disableMimes = {},      -- Unsupported file mimes by the script
	single_or_multi = "",   -- Script to support either "single" or "multi" file, or both.
}
return config

init.lua

The init.lua file contains the main logic of the script. Here’s an example:

local M = {}

--luacheck: ignore output err
function M.init(_, opts)
	-- stylua: ignore
	-- The script here won't work without "./"
	-- The script file must have execution permissions
	local output, err = Command("./blablabla.sh")
		:cwd(opts.workpath) -- Enter the directory of the action plugin
		-- To avoid issues with spaces in filenames, here we use Tab to separate
		-- Therefore, in the script file, it must declare IFS=$'\t'
		:env("selection", table.concat(opts.selected, "\t"))
		:output()

	-- For detailed usage of the 'output' and 'err' variables,
	-- please refer to: https://yazi-rs.github.io/docs/plugins/utils#output
end

return M

Execution Script Example

#!/usr/bin/env bash
set -e
IFS=$'\t'
# Setting the Internal Field Separator (IFS) to a tab character to handle file names with spaces.

OS="$(uname -s)"
case "$OS" in
	Darwin) echo "Mac" ;;
	Linux) echo "Linux" ;;
	*) echo "Unsupported operating system"; exit 1 ;;
esac

# Loop through the list of selected files.
for file in ${selection}; do
	echo "$file" 
done

This script is a basic template and should be modified according to the specific needs of your action scripts. Make sure to test the script in your environment before using it in production.

Directory Structure

~/.config/yazi/
├── init.lua
├── plugins/
│   └── file-actions.yazi/
│       ├── init.lua
│       └── actions/
│           ├── action1/
│           │   ├── init.lua
│           │   ├── info.lua
│           │   └── blabla.sh
│           └── action2/
│               ├── init.lua
│               ├── info.lua
│               └── blabla.sh
└── yazi.toml
f13b4a91d5042bbced946137703cce48.mp4

file-actions.yazi's People

Contributors

bbooxx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.