diff options
author | toonn <toonn@toonn.io> | 2019-12-31 15:10:37 +0100 |
---|---|---|
committer | toonn <toonn@toonn.io> | 2019-12-31 15:10:37 +0100 |
commit | 73b9d457d461d9f242f0dfb14643c08c0377193b (patch) | |
tree | 65f28651cf34e4e5dff4fd9c31462dd896c99e88 /examples/shell_automatic_cd.sh | |
parent | 219413fa6fa8ff103a633bebf8535768456a5be6 (diff) | |
parent | 5dc0d60a56679da5f98cfc8a03273ccafa6d016a (diff) | |
download | ranger-73b9d457d461d9f242f0dfb14643c08c0377193b.tar.gz |
Merge branch 'dmitmel-examples-bash-automatic-cd'
Diffstat (limited to 'examples/shell_automatic_cd.sh')
-rw-r--r-- | examples/shell_automatic_cd.sh | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/shell_automatic_cd.sh b/examples/shell_automatic_cd.sh new file mode 100644 index 00000000..391946c7 --- /dev/null +++ b/examples/shell_automatic_cd.sh @@ -0,0 +1,23 @@ +# shellcheck shell=sh + +# Compatible with ranger 1.4.2 through 1.9.* +# +# Automatically change the current working directory after closing ranger +# +# This is a shell function to automatically change the current working +# directory to the last visited one after ranger quits. Either put it into your +# .zshrc/.bashrc/etc or source this file from your shell configuration. +# To undo the effect of this function, you can type "cd -" to return to the +# original directory. + +ranger_cd() { + temp_file="$(mktemp -t "ranger_cd.XXXXXXXXXX")" + ranger --choosedir="$temp_file" -- "${@:-$PWD}" + if chosen_dir="$(cat -- "$temp_file")" && [ -n "$chosen_dir" ] && [ "$chosen_dir" != "$PWD" ]; then + cd -- "$chosen_dir" + fi + rm -f -- "$temp_file" +} + +# This binds Ctrl-O to ranger-cd: +bind '"\C-o":"ranger-cd\C-m"' |