Last active
May 14, 2021 22:01
-
-
Save Gosha/6fb88be3e69d093139e50a3146952d88 to your computer and use it in GitHub Desktop.
Insert file paths chosen with ranger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Demo: https://delad.besvikel.se/s/2021-05/tR5WYRsNfD.mp4