Skip to content

Instantly share code, notes, and snippets.

@Lutzifer
Last active April 1, 2020 09:06
Show Gist options
  • Save Lutzifer/68ec093c063124de89dd9f63ae2e1fb4 to your computer and use it in GitHub Desktop.
Save Lutzifer/68ec093c063124de89dd9f63ae2e1fb4 to your computer and use it in GitHub Desktop.
Interactive version of zsh's wd (warp/working directory) feature.
#!/bin/zsh
wd () {
source "$ZSH/plugins/wd/wd.sh"
}
CHOICES=( $(wd list | cut -d ">" -f 1 | sed "s/ -//g" | sed 's/^ *//g' | sed 's/ *$//g' | tail -n +2 | awk '{printf $0 " "}') )
PS3="Please enter your choice: "
select ANSWER in "${CHOICES[@]}"; do
for ITEM in "${CHOICES[@]}"; do
if [[ $ITEM == $ANSWER ]]; then
break 2
fi
done
done
TARGET_PATH="$(wd list | grep "$ANSWER " | cut -d ">" -f 2 | sed "s/ -//g" | sed 's/^ *//g' | sed 's/ *$//g' | awk '{printf $0 " "}')"
REAL_PATH="$(eval echo $TARGET_PATH)"
echo $REAL_PATH
cd $REAL_PATH
ls
@Lutzifer
Copy link
Author

Lutzifer commented Apr 1, 2020

Add an alias like alias iwd='. ~/iwd.sh' and invoke it with iwd for interactive selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment