|
|
|
|
@ -8,7 +8,7 @@ |
|
|
|
|
# @github.com/mfaerevaag/wd |
|
|
|
|
|
|
|
|
|
# version |
|
|
|
|
readonly WD_VERSION=0.6.1 |
|
|
|
|
readonly WD_VERSION=0.7.0 |
|
|
|
|
|
|
|
|
|
# colors |
|
|
|
|
readonly WD_BLUE="\033[96m" |
|
|
|
|
@ -59,7 +59,7 @@ wd_print_msg() |
|
|
|
|
then |
|
|
|
|
local color="${1:-$WD_BLUE}" # Default to blue if no color is provided |
|
|
|
|
local msg="$2" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [[ -z "$msg" ]]; then |
|
|
|
|
print "${WD_RED}*${WD_NOC} Could not print message. Sorry!" |
|
|
|
|
else |
|
|
|
|
@ -74,18 +74,20 @@ wd_print_usage() |
|
|
|
|
Usage: wd [command] [point] |
|
|
|
|
|
|
|
|
|
Commands: |
|
|
|
|
<point> Warps to the directory specified by the warp point |
|
|
|
|
<point> <path> Warps to the directory specified by the warp point with path appended |
|
|
|
|
add <point> Adds the current working directory to your warp points |
|
|
|
|
add Adds the current working directory to your warp points with current directory's name |
|
|
|
|
rm <point> Removes the given warp point |
|
|
|
|
rm Removes the given warp point with current directory's name |
|
|
|
|
show <point> Print path to given warp point |
|
|
|
|
show Print warp points to current directory |
|
|
|
|
list Print all stored warp points |
|
|
|
|
ls <point> Show files from given warp point (ls) |
|
|
|
|
path <point> Show the path to given warp point (pwd) |
|
|
|
|
clean Remove points warping to nonexistent directories (will prompt unless --force is used) |
|
|
|
|
<point> Warps to the directory specified by the warp point |
|
|
|
|
<point> <path> Warps to the directory specified by the warp point with path appended |
|
|
|
|
add <point> Adds the current working directory to your warp points |
|
|
|
|
add Adds the current working directory to your warp points with current directory's name |
|
|
|
|
addcd <path> Adds a path to your warp points with the directory's name |
|
|
|
|
addcd <path> <point> Adds a path to your warp points with a custom name |
|
|
|
|
rm <point> Removes the given warp point |
|
|
|
|
rm Removes the given warp point with current directory's name |
|
|
|
|
show <point> Print path to given warp point |
|
|
|
|
show Print warp points to current directory |
|
|
|
|
list Print all stored warp points |
|
|
|
|
ls <point> Show files from given warp point (ls) |
|
|
|
|
path <point> Show the path to given warp point (pwd) |
|
|
|
|
clean Remove points warping to nonexistent directories (will prompt unless --force is used) |
|
|
|
|
|
|
|
|
|
-v | --version Print version |
|
|
|
|
-d | --debug Exit after execution with exit codes (for testing) |
|
|
|
|
@ -203,6 +205,28 @@ wd_add() |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wd_addcd() { |
|
|
|
|
local folder="$1" |
|
|
|
|
local point=$2 |
|
|
|
|
local force=$3 |
|
|
|
|
local currentdir=$PWD |
|
|
|
|
|
|
|
|
|
if [[ -z "$folder" ]]; then |
|
|
|
|
wd_exit_fail "You must specify a path" |
|
|
|
|
return |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
if [[ ! -d "$folder" ]]; then |
|
|
|
|
wd_exit_fail "The directory does not exist" |
|
|
|
|
return |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
cd "$folder" || return |
|
|
|
|
wd_add "$point" "$force" |
|
|
|
|
cd "$currentdir" || return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wd_remove() |
|
|
|
|
{ |
|
|
|
|
local point_list=$1 |
|
|
|
|
@ -235,7 +259,15 @@ wd_browse() { |
|
|
|
|
return 1 |
|
|
|
|
fi |
|
|
|
|
local entries=("${(@f)$(sed "s:${HOME}:~:g" "$WD_CONFIG" | awk -F ':' '{print $1 " -> " $2}')}") |
|
|
|
|
local selected_entry=$(printf '%s\n' "${entries[@]}" | fzf --height 40% --reverse) |
|
|
|
|
local script_path="${${(%):-%x}:h}" |
|
|
|
|
local wd_remove_output=$(mktemp "${TMPDIR:-/tmp}/wd.XXXXXXXXXX") |
|
|
|
|
local entries_with_headers=("All warp points:" "Press enter to select. Press delete to remove" "${entries[@]}") |
|
|
|
|
local fzf_bind="delete:execute(echo {} | awk -F ' -> ' '{print \$1}' | xargs -I {} "$script_path/wd.sh" rm {} > "$wd_remove_output")+abort" |
|
|
|
|
local fzf_command=$(printf '%s\n' "${entries_with_headers[@]}" | fzf --height 100% --reverse --header-lines=2 --bind="$fzf_bind") |
|
|
|
|
if [[ -e $wd_remove_output ]]; then |
|
|
|
|
cat "$wd_remove_output" |
|
|
|
|
rm "$wd_remove_output" |
|
|
|
|
fi |
|
|
|
|
if [[ -n $selected_entry ]]; then |
|
|
|
|
local selected_point="${selected_entry%% ->*}" |
|
|
|
|
selected_point=$(echo "$selected_point" | xargs) |
|
|
|
|
@ -243,6 +275,24 @@ wd_browse() { |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wd_browse_widget() { |
|
|
|
|
if [[ -e $WD_CONFIG ]]; then |
|
|
|
|
wd_browse |
|
|
|
|
saved_buffer=$BUFFER |
|
|
|
|
saved_cursor=$CURSOR |
|
|
|
|
BUFFER= |
|
|
|
|
zle redisplay |
|
|
|
|
zle accept-line |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wd_restore_buffer() { |
|
|
|
|
BUFFER=$saved_buffer |
|
|
|
|
CURSOR=$saved_cursor |
|
|
|
|
saved_buffer= |
|
|
|
|
saved_cursor=1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
wd_list_all() |
|
|
|
|
{ |
|
|
|
|
wd_print_msg "$WD_BLUE" "All warp points:" |
|
|
|
|
@ -371,7 +421,7 @@ wd_export_static_named_directories() { |
|
|
|
|
fi |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc} |
|
|
|
|
WD_CONFIG=${WD_CONFIG:-$HOME/.warprc} |
|
|
|
|
local WD_QUIET=0 |
|
|
|
|
local WD_EXIT_CODE=0 |
|
|
|
|
local WD_DEBUG=0 |
|
|
|
|
@ -455,6 +505,10 @@ else |
|
|
|
|
wd_browse |
|
|
|
|
break |
|
|
|
|
;; |
|
|
|
|
"-c"|"--addcd"|"addcd") |
|
|
|
|
wd_addcd "$2" "$3" "$wd_force_mode" |
|
|
|
|
break |
|
|
|
|
;; |
|
|
|
|
"-e"|"export") |
|
|
|
|
wd_export_static_named_directories |
|
|
|
|
break |
|
|
|
|
@ -510,6 +564,7 @@ fi |
|
|
|
|
unset wd_extglob_is_set |
|
|
|
|
unset wd_warp |
|
|
|
|
unset wd_add |
|
|
|
|
unset wd_addcd |
|
|
|
|
unset wd_remove |
|
|
|
|
unset wd_show |
|
|
|
|
unset wd_list_all |
|
|
|
|
|