2016-08-30 13:20:12 +02:00
|
|
|
# http://ranger.nongnu.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command ranger-open-on-edit-directory \
|
2016-10-11 09:03:41 +02:00
|
|
|
-docstring 'Start the ranger file system explorer when trying to edit a directory' %{
|
2018-05-06 23:29:52 +02:00
|
|
|
hook global RuntimeError "\d+:\d+: '\w+' (.*): is a directory" %{ evaluate-commands %sh{
|
2017-11-29 18:17:45 +01:00
|
|
|
directory=$kak_hook_param_capture_1
|
|
|
|
echo ranger $directory
|
2016-09-28 20:34:16 +02:00
|
|
|
}}
|
|
|
|
}
|
2016-08-30 13:20:12 +02:00
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command \
|
2017-11-29 18:17:45 +01:00
|
|
|
-params .. -file-completion \
|
|
|
|
-docstring %{ranger [<arguments>]: open the file system explorer to select buffers to open
|
|
|
|
All the optional arguments are forwarded to the ranger utility} \
|
2018-05-06 23:29:52 +02:00
|
|
|
ranger %{ evaluate-commands %sh{
|
2017-11-29 18:17:45 +01:00
|
|
|
if [ -n "${TMUX}" ]; then
|
|
|
|
tmux split-window -h \
|
|
|
|
ranger $@ --cmd " \
|
|
|
|
map <return> eval \
|
|
|
|
fm.execute_console('shell \
|
|
|
|
echo evaluate-commands -client ' + ranger.ext.shell_escape.shell_escape('$kak_client') + ' edit {file} | \
|
|
|
|
kak -p '.format(file=fm.thisfile.path) + ranger.ext.shell_escape.shell_escape('$kak_session') + '; \
|
|
|
|
tmux select-pane -t $kak_client_env_TMUX_PANE') \
|
|
|
|
if fm.thisfile.is_file else fm.execute_console('move right=1')"
|
2017-11-17 20:40:42 +01:00
|
|
|
|
2017-11-29 18:17:45 +01:00
|
|
|
elif [ -n "${STY}" ]; then
|
2017-11-17 20:40:42 +01:00
|
|
|
|
2017-11-29 18:17:45 +01:00
|
|
|
script="/tmp/kak-ranger-${kak_client}-${kak_session}.sh"
|
|
|
|
selections="/tmp/kak-ranger-${kak_client}-${kak_session}.txt"
|
|
|
|
cat > "$script" << EOF
|
2017-11-17 20:40:42 +01:00
|
|
|
#! /usr/bin/env sh
|
|
|
|
cd "$PWD"
|
|
|
|
ranger --choosefiles="$selections" $@
|
|
|
|
while read -r f; do
|
|
|
|
printf %s "evaluate-commands -client '${kak_client}' edit '\"\$f\"'" | kak -p '${kak_session}'
|
|
|
|
done < "$selections"
|
|
|
|
screen -X remove
|
|
|
|
rm -f "$selections" "$script"
|
|
|
|
EOF
|
|
|
|
|
|
|
|
tty="$(ps -o tty ${kak_client_pid} | tail -n 1)"
|
|
|
|
screen -X eval \
|
|
|
|
'split -h' \
|
|
|
|
'focus down' \
|
|
|
|
"screen sh '$script'" \
|
|
|
|
< "/dev/$tty"
|
|
|
|
|
2017-11-29 18:17:45 +01:00
|
|
|
elif [ -n "$WINDOWID" ]; then
|
|
|
|
setsid $kak_opt_termcmd " \
|
|
|
|
ranger $@ --cmd "'"'" \
|
|
|
|
map <return> eval \
|
|
|
|
fm.execute_console('shell \
|
|
|
|
echo evaluate-commands -client ' + ranger.ext.shell_escape.shell_escape('$kak_client') + ' edit {file} | \
|
|
|
|
kak -p '.format(file=fm.thisfile.path) + ranger.ext.shell_escape.shell_escape('$kak_session') + '; \
|
|
|
|
xdotool windowactivate $kak_client_env_WINDOWID') \
|
|
|
|
if fm.thisfile.is_file else fm.execute_console('move right=1')"'"' < /dev/null > /dev/null 2>&1 &
|
|
|
|
fi
|
2016-08-30 13:20:12 +02:00
|
|
|
}}
|