From 13b258a8e3b9d17a0b110779531c63afa8a18c43 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Mon, 29 Apr 2024 00:00:19 +0200 Subject: [PATCH] jumpv2 --- users/pbsds/home/modules/jump.nix | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/users/pbsds/home/modules/jump.nix b/users/pbsds/home/modules/jump.nix index e48dd3b..2d91f0f 100644 --- a/users/pbsds/home/modules/jump.nix +++ b/users/pbsds/home/modules/jump.nix @@ -35,26 +35,29 @@ in { programs = let rcScript = '' - function jump { - if test -z "$1"; then - 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 + function _mark_choose() { + ${lib.getExe pkgs.fd} . "$_JUMP_MARKPATH" --type l -X ${lib.getExe pkgs.gum} choose --ordered {/} + } + function jump() { + local target="''${1:-$(_mark_choose)}" + if test -n "$target"; then pushd . > /dev/null - cd -P "$_JUMP_MARKPATH/$1" 2>/dev/null || echo "No such mark: $1" + cd -P "$_JUMP_MARKPATH/$target" 2>/dev/null || echo "No such mark: $target" fi } - function mark { + function mark() { mkdir -p "$_JUMP_MARKPATH" && test ! -L "$_JUMP_MARKPATH/$1" \ && ln -s "$(pwd)" "$_JUMP_MARKPATH/$1" \ || echo "mark already exists!" } - function unmark { - test ! -z "$1" \ - && rm -i "$_JUMP_MARKPATH/$1" + function unmark() { + local target="''${1:-$(_mark_choose)}" + if test -n "$target"; then + rm -i "$_JUMP_MARKPATH/$target" + fi } - function marks { + function marks() { #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 ' -> ' }