Skip to content

Commit

Permalink
Use sed instead of grep | awk | cut
Browse files Browse the repository at this point in the history
Also don't check for git repo on `wt names`.
  • Loading branch information
mateusauler committed Jul 25, 2024
1 parent 8432386 commit 0cbb85b
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions wt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ CHANGE_DIRECTORY_PREFIX="changedir:"
arg=${args[0]/\//\\\/}

worktree_list_names() {
if git rev-parse --git-dir &> /dev/null; then
git worktree list --porcelain \
| awk '/^worktree / { sub("worktree ", ""); print; }' \
| xargs -I{} basename {}
fi
git worktree list --porcelain | sed -n 's/^worktree\s*//p' | xargs -r -I{} basename {}
}

help_message() {
Expand Down Expand Up @@ -184,7 +180,7 @@ init)
init
;;
*)
directory=$(git worktree list --porcelain | grep -E 'worktree ' | awk '/'"$arg"'/ {print; exit}' | cut -d ' ' -f2-)
directory=$(git worktree list --porcelain | sed -n '/'"${arg:-.}"'/{s/^worktree\s*//p;q}')
;;
esac

Expand Down

0 comments on commit 0cbb85b

Please sign in to comment.