jump: use gum

This commit is contained in:
Peder Bergebakken Sundt 2024-02-01 00:58:20 +01:00
parent 4336b974a4
commit 75d95fe20e
1 changed files with 14 additions and 9 deletions

View File

@ -36,26 +36,31 @@ in {
programs = let programs = let
rcScript = '' rcScript = ''
function jump { function jump {
pushd . > /dev/null if test -z "$1"; then
cd -P "$_JUMP_MARKPATH/$1" 2>/dev/null || echo "No such mark: $1" test -n "$_JUMP_RECURSE" && return 1
_JUMP_RECURSE=1 jump "$(${lib.getExe pkgs.fd} . "$_JUMP_MARKPATH" --type l -X ${lib.getExe pkgs.gum} choose --ordered {/})"
else
pushd . > /dev/null
cd -P "$_JUMP_MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
fi
} }
function mark { function mark {
mkdir -p "$_JUMP_MARKPATH" && mkdir -p "$_JUMP_MARKPATH" &&
test ! -L "$_JUMP_MARKPATH/$1" \ test ! -L "$_JUMP_MARKPATH/$1" \
&& ln -s "$(pwd)" "$_JUMP_MARKPATH/$1" \ && ln -s "$(pwd)" "$_JUMP_MARKPATH/$1" \
|| echo "mark already exists!" || echo "mark already exists!"
} }
function unmark { function unmark {
test ! -z "$1" \ test ! -z "$1" \
&& rm -i "$_JUMP_MARKPATH/$1" && rm -i "$_JUMP_MARKPATH/$1"
} }
function marks { function marks {
#ls -l "$_JUMP_MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo #ls -l "$_JUMP_MARKPATH" | sed 's/ / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
command ls --color=always -l "$_JUMP_MARKPATH" | tr -s ' ' | cut -d' ' -f9- | sed -e 's/ -> /§/g' | column -t -s '§' -o ' -> ' command ls --color=always -l "$_JUMP_MARKPATH" | tr -s ' ' | cut -d' ' -f9- | sed -e 's/ -> /§/g' | column -t -s '§' -o ' -> '
} }
_complete_jump_marks() { _complete_jump_marks() {
local curw=''${COMP_WORDS[COMP_CWORD]} local curw=''${COMP_WORDS[COMP_CWORD]}
local wordlist=$(find $_JUMP_MARKPATH -type l -printf "%f\n") local wordlist=$(find "$_JUMP_MARKPATH" -type l -printf "%f\n")
COMPREPLY=($(compgen -W ''\'''${wordlist[@]}' -- "$curw")) COMPREPLY=($(compgen -W ''\'''${wordlist[@]}' -- "$curw"))
return 0 return 0
} }