Merge pull request #930 from exoton/cdpath

Truncate the name, add comments.
This commit is contained in:
Mischievous Meerkat 2021-03-30 08:32:47 +05:30 committed by GitHub
commit e459d912b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,22 +10,24 @@
# The fzf search is done on the directory basename (the first column). # The fzf search is done on the directory basename (the first column).
# #
# This plugin is an extended version of the bookmarks plugin. # This plugin is an extended version of the bookmarks plugin.
# If you set your CDPATH to ${XDG_CACHE_HOME:-$HOME/.cache}/nnn/bookmarks
# or to the value of BOOKMARKS_DIR, you can use it as a bookmarks replacement.
# #
# Shell: POSIX compliant # Shell: POSIX compliant
# Author: Yuri Kloubakov # Author: Yuri Kloubakov
. "$(dirname "$0")"/.nnn-plugin-helper . "$(dirname "$0")"/.nnn-plugin-helper
# Get a list of (symbolic links to) directories for every element of CDPATH
get_dirs() { get_dirs() {
# Get a list of directories and symbolic links to directories
IFS=':' IFS=':'
for path in $CDPATH; do for path in $CDPATH; do
for entry in "$path"/*; do for entry in "$path"/*; do
if [ -d "$entry" ]; then if [ -d "$entry" ]; then
name="$(basename "$entry")" name=$(basename "$entry" | grep -o '^.\{1,24\}')
if [ -h "$entry" ]; then if [ -h "$entry" ]; then
l="$(ls -dl "$entry")" slink=$(ls -dl -- "$entry")
entry="${l#*"${entry} -> "}" entry=${slink#*" $entry -> "}
fi fi
printf "%-24s :%s\n" "${name}" "$entry" printf "%-24s :%s\n" "${name}" "$entry"
fi fi
@ -44,10 +46,10 @@ if [ -z "$CDPATH" ]; then
[ -d "$CDPATH" ] || abort "CDPATH is not set and there is no \"$CDPATH\" directory" [ -d "$CDPATH" ] || abort "CDPATH is not set and there is no \"$CDPATH\" directory"
fi fi
dir_list="$(get_dirs)" dir_list=$(get_dirs)
[ -n "$dir_list" ] || abort "There are no directories to choose from. Check your \"$CDPATH\"." [ -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 }')" dir=$(echo "$dir_list" | fzf --nth=1 --delimiter=':' | awk -F: 'END { print $2 }')
if [ -n "$dir" ]; then if [ -n "$dir" ]; then
nnn_cd "$dir" 0 nnn_cd "$dir" 0
fi fi