mirror of
https://github.com/jarun/nnn.git
synced 2024-10-31 16:37:18 +00:00
Add new plugin (#928)
* Add new plugin * Small cdpath refactoring * Change the default CDPATH value, remove string indexing. * Remove readlink() call to be POSIX compliant. * Fix the comment
This commit is contained in:
parent
832676984b
commit
42aa97b112
|
@ -17,6 +17,7 @@ Plugins extend the capabilities of `nnn`. They are _executable_ scripts (or bina
|
|||
| [bookmarks](bookmarks) | Use named bookmarks managed with symlinks | sh | fzf |
|
||||
| [boom](boom) | Play random music from dir | sh | [moc](http://moc.daper.net/) |
|
||||
| [bulknew](bulknew) | Create multiple files/dirs at once | bash | sed, xargs, mktemp |
|
||||
| [cdpath](cdpath) | `cd` to the directory from `CDPATH` | sh | fzf |
|
||||
| [chksum](chksum) | Create and verify checksums [✓] | sh | md5sum,<br>sha256sum |
|
||||
| [cleanfilename](cleanfilename) | Clean filename to be more shell-friendly [✓] | bash | sed |
|
||||
| [diffs](diffs) | Diff for selection (limited to 2 for directories) [✓] | sh | vimdiff, mktemp |
|
||||
|
|
53
plugins/cdpath
Executable file
53
plugins/cdpath
Executable file
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
# Description: 'cd' to the directory from CDPATH
|
||||
#
|
||||
# Details: If the CDPATH environmet variable is not set, the default value of
|
||||
# ${XDG_CONFIG_HOME:-$HOME/.config}/nnn/bookmarks will be used.
|
||||
# You can create this directory and fill it with symbolic links to your
|
||||
# favorite directories. It's a good idea to add it to CDPATH so that it
|
||||
# could also be used from the command line outside of nnn.
|
||||
# The fzf search is done on the directory basename (the first column).
|
||||
#
|
||||
# This plugin is an extended version of the bookmarks plugin.
|
||||
#
|
||||
# Shell: POSIX compliant
|
||||
# Author: Yuri Kloubakov
|
||||
|
||||
. "$(dirname "$0")"/.nnn-plugin-helper
|
||||
|
||||
get_dirs() {
|
||||
# Get a list of directories and symbolic links to directories
|
||||
IFS=':'
|
||||
for path in $CDPATH; do
|
||||
for entry in "$path"/*; do
|
||||
if [ -d "$entry" ]; then
|
||||
name="$(basename "$entry")"
|
||||
if [ -h "$entry" ]; then
|
||||
l="$(ls -dl "$entry")"
|
||||
entry="${l#*"${entry} -> "}"
|
||||
fi
|
||||
printf "%-24s :%s\n" "${name}" "$entry"
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
abort() {
|
||||
echo "$1"
|
||||
read -r _
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ -z "$CDPATH" ]; then
|
||||
CDPATH="${XDG_CONFIG_HOME:-$HOME/.config}/nnn/bookmarks"
|
||||
[ -d "$CDPATH" ] || abort "CDPATH is not set and there is no \"$CDPATH\" directory"
|
||||
fi
|
||||
|
||||
dir_list="$(get_dirs)"
|
||||
[ -n "$dir_list" ] || abort "There are no directories to choose from. Check your \"$CDPATH\"."
|
||||
|
||||
dir="$(echo "$dir_list" | fzf --nth=1 --delimiter=':' | awk -F: 'END { print $2 }')"
|
||||
if [ -n "$dir" ]; then
|
||||
nnn_cd "$dir" 0
|
||||
fi
|
Loading…
Reference in a new issue