Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wd): update to version v0.6.1 #12413

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies:
plugins/wd:
repo: mfaerevaag/wd
branch: master
version: tag:v0.6.0
version: tag:v0.6.1
precopy: |
set -e
rm -r test
Expand Down
28 changes: 27 additions & 1 deletion plugins/wd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ wd() {
}
```

### [Home Manager](https://github.com/nix-community/home-manager)

Add the following to your `home.nix` then run `home-manager switch`:

```nix
programs.zsh.plugins = [
{
name = "wd";
src = pkgs.fetchFromGitHub {
owner = "mfaerevaag";
repo = "wd";
rev = "v0.5.2";
sha256 = "sha256-4yJ1qhqhNULbQmt6Z9G22gURfDLe30uV1ascbzqgdhg=";
};
}
];
```

### [zplug](https://github.com/zplug/zplug)

```zsh
Expand Down Expand Up @@ -119,6 +137,14 @@ Also, you may have to force a rebuild of `zcompdump` by running:
rm -f ~/.zcompdump; compinit
```

## Browse

If you want to make use of the `fzf`-powered browse feature to fuzzy search through all your warp points, set up a keybind in your `.zshrc`:

```zsh
bindkey '^G' wd_browse
```

## Usage

* Add warp point to current working directory:
Expand Down Expand Up @@ -153,7 +179,7 @@ wd ..
wd ...
```

This is a wrapper for the zsh's `dirs` function.
This is a wrapper for the zsh's `dirs` function.
_You might need to add `setopt AUTO_PUSHD` to your `.zshrc` if you are not using [oh-my-zsh](https://github.com/ohmyzsh/ohmyzsh)._

* Remove warp point:
Expand Down
7 changes: 6 additions & 1 deletion plugins/wd/wd.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
# @github.com/mfaerevaag/wd

# Handle $0 according to the standard:
# https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
# # https://zdharma-continuum.github.io/Zsh-100-Commits-Club/Zsh-Plugin-Standard.html
0="${${ZERO:-${0:#$ZSH_ARGZERO}}:-${(%):-%N}}"
0="${${(M)0:#/*}:-$PWD/$0}"

eval "wd() { source '${0:A:h}/wd.sh' }"
wd > /dev/null
# Register the function as a Zsh widget
zle -N wd_browse
# Bind the widget to a key combination
bindkey '^G' wd_browse
37 changes: 29 additions & 8 deletions plugins/wd/wd.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# @github.com/mfaerevaag/wd

# version
readonly WD_VERSION=0.5.0
readonly WD_VERSION=0.6.1

# colors
readonly WD_BLUE="\033[96m"
Expand Down Expand Up @@ -57,12 +57,11 @@ wd_print_msg()
{
if [[ -z $wd_quiet_mode ]]
then
local color=$1
local msg=$2
local color="${1:-$WD_BLUE}" # Default to blue if no color is provided
local msg="$2"

if [[ $color == "" || $msg == "" ]]
then
print " ${WD_RED}*${WD_NOC} Could not print message. Sorry!"
if [[ -z "$msg" ]]; then
print "${WD_RED}*${WD_NOC} Could not print message. Sorry!"
else
print " ${color}*${WD_NOC} ${msg}"
fi
Expand Down Expand Up @@ -230,6 +229,20 @@ wd_remove()
done
}

wd_browse() {
if ! command -v fzf >/dev/null; then
echo "This functionality requires fzf. Please install fzf first."
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)
if [[ -n $selected_entry ]]; then
local selected_point="${selected_entry%% ->*}"
selected_point=$(echo "$selected_point" | xargs)
wd $selected_point
fi
}

wd_list_all()
{
wd_print_msg "$WD_BLUE" "All warp points:"
Expand Down Expand Up @@ -396,7 +409,9 @@ fi
# disable extendedglob for the complete wd execution time
setopt | grep -q extendedglob
wd_extglob_is_set=$?
(( ! $wd_extglob_is_set )) && setopt noextendedglob
if (( wd_extglob_is_set == 0 )); then
setopt noextendedglob
fi

# load warp points
typeset -A points
Expand Down Expand Up @@ -436,6 +451,10 @@ else
wd_add "$2" "$wd_force_mode"
break
;;
"-b"|"browse")
wd_browse
break
;;
"-e"|"export")
wd_export_static_named_directories
break
Expand Down Expand Up @@ -484,7 +503,9 @@ fi
# if not, next time warp will pick up variables from this run
# remember, there's no sub shell

(( ! $wd_extglob_is_set )) && setopt extendedglob
if (( wd_extglob_is_set == 0 )); then
setopt extendedglob
fi

unset wd_extglob_is_set
unset wd_warp
Expand Down