Skip to content

Commit

Permalink
[bin] Fix -L handling in pcd.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mina86 committed Jun 2, 2024
1 parent a8e20fb commit 7521788
Showing 1 changed file with 34 additions and 32 deletions.
66 changes: 34 additions & 32 deletions bin/pcd.sh
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
# shellcheck shell=sh disable=SC2164

cd() {
case "$#:$1" in
1:-h)
case $#:$1 in
0:)
command cd
return
;;

1:--help)
cat <<EOF
cd Move to home directory.
cd -P Resolve all symbolic links in \$PWD.
cd [-L | -P | --] <target> Move to given <target>.
cd [-L | -P | --] <target> <cmd> ... Run <cmd> in the given <target>.
Usage:
cd Move to home directory.
cd -P Resolve all symbolic links in \$PWD.
cd [-L | -P | --] <target> Move to given <target>.
cd [-L | -P | --] <target> <cmd>... Run <cmd> in the given <target>.
<target> can be:
- Move to directory stored in \$OLDPWD
.../<path> Move to a sibling/cusing directory <path>; this will iterate
up the directories until <path> is located
<file> Move to directory containing the file
<dir> Move to given directory
- Move to directory stored in \$OLDPWD.
.../<path> Move to a sibling/cusing directory <path>; this will iterate
up the directories until <path> is located.
<file> Move to directory containing the file.
<dir> Move to given directory.
EOF
return
;;
0:)
command cd
;;

1:-[LP])
command cd "$1" "${PWD}"
set -- "$1" "${PWD}"
;;
1:*)
_cd_do -L "$1"
;;
2:--)
_cd_do -L "$2"
;;
2:-[LP])
_cd_do "$1" "$2"
;;
*)
if [ "$1" = -- ]; then
shift
set -- -L "$@"
elif [ "$1" != -P ]; then
set -- -L "$@"
fi
( _cd_do "$1" "$2" && shift 2 && exec "$@" )
set -- -L "$1"
esac

case $1 in
--) shift; set -- -L "$@"; ;;
-[LP]) :; ;;
*) set -- -L "$@"
esac

if [ $# -eq 2 ]; then
_cd_do "$@"
else
( _cd_do "$1" "$2" && shift 2 && exec "$@" )
fi
}

_cd_do() {
case "$2" in
case $2 in
-)
:
;;
Expand Down

0 comments on commit 7521788

Please sign in to comment.