diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2020-12-14 06:55:51 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2020-12-14 07:52:35 +0300 |
commit | 5c31078043810ce883254de72f738a06e12e4554 (patch) | |
tree | 2a3068c6301833f19ccdd3f62e30c2a4f1bf577f /%HOME%/.config/nnn/plugins/myfzcd | |
parent | ranger: fuzzy-search hidden files also (diff) | |
download | linux-home-5c31078043810ce883254de72f738a06e12e4554.tar.gz linux-home-5c31078043810ce883254de72f738a06e12e4554.zip |
add nnn configuration
Diffstat (limited to '%HOME%/.config/nnn/plugins/myfzcd')
-rwxr-xr-x | %HOME%/.config/nnn/plugins/myfzcd | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/%HOME%/.config/nnn/plugins/myfzcd b/%HOME%/.config/nnn/plugins/myfzcd new file mode 100755 index 0000000..36bfb24 --- /dev/null +++ b/%HOME%/.config/nnn/plugins/myfzcd @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# Like the fzcd plugin, but better. + +set -o errexit -o pipefail + +if command -v fzf > /dev/null 2>&1; then + sel="$( fzf )" +else + exit 1 +fi + +nnn_cd() { + dir="$1" + + if [ -z "$NNN_PIPE" ]; then + echo "No pipe file found" >&2 + return + fi + + printf -- '%s' "0c$dir" > "$NNN_PIPE" +} + + +if [ -n "$sel" ]; then + if [ ! -d "$sel" ]; then + sel="$( dirname -- "$sel" )" + elif [ "$sel" = . ]; then + exit 0 + fi + + case "$sel" in + /*) + nnn_cd "$sel" + ;; + *) + sel="${sel#./}" + + if [ "$PWD" = "/" ]; then + nnn_cd "/$sel" + else + nnn_cd "$PWD/$sel" + fi + ;; + esac +fi |