0
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-09-19 04:01:21 +02:00

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

Co-authored-by: ohmyzsh[bot] <54982679+ohmyzsh[bot]@users.noreply.github.com>
This commit is contained in:
ohmyzsh[bot] 2024-05-12 12:42:59 +02:00 committed by GitHub
parent 0493eab8ce
commit b1c5315a5f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 63 additions and 11 deletions

View file

@ -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

View file

@ -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
@ -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:

View file

@ -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
plugins/wd/wd.sh Normal file → Executable file
View file

@ -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"
@ -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
@ -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:"
@ -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
@ -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
@ -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