Skip to content

Instantly share code, notes, and snippets.

@Gosha
Last active May 14, 2021 22:01
Show Gist options
  • Save Gosha/6fb88be3e69d093139e50a3146952d88 to your computer and use it in GitHub Desktop.
Save Gosha/6fb88be3e69d093139e50a3146952d88 to your computer and use it in GitHub Desktop.
Insert file paths chosen with ranger
# Insert file paths chosen with ranger
# Default bound to <c-p>
# If cursor is on a file, press either <enter> or <a-enter> to finish
# If cursor is on a directory, press <a-enter> to finish
ranger-insert-files-widget () {
local tmpfile=$(mktemp)
ranger --choosefiles=${tmpfile} --cmd "map <a-enter> execute_file a" < $TTY
local files=$(cat $tmpfile | while read line
do
local item=$(realpath --no-symlinks --relative-to=$(pwd) "${line}")
echo -n "${(q)item} "
done
)
LBUFFER="${LBUFFER}${files}"
local ret=$?
rm $tmpfile
zle reset-prompt
return $ret
}
zle -N ranger-insert-files-widget
bindkey '^P' ranger-insert-files-widget
@Gosha
Copy link
Author

Gosha commented May 14, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment