Skip to content

Commit 1ea22d6

Browse files
committed
Shorter version
1 parent 880c817 commit 1ea22d6

File tree

1 file changed

+1
-30
lines changed

1 file changed

+1
-30
lines changed

upto.sh

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
#!/bin/bash
2-
function upto() {
3-
local EXPRESSION="$1"
4-
if [ -z "$EXPRESSION" ]; then
5-
echo "A folder expression must be provided." >&2
6-
return 1
7-
fi
8-
if [ "$EXPRESSION" = "/" ]; then
9-
cd "/"
10-
return 0
11-
fi
12-
local CURRENT_FOLDER="$(pwd)"
13-
local MATCHED_DIR=""
14-
local MATCHING=true
15-
16-
while [ "$MATCHING" = true ]; do
17-
if [[ "$CURRENT_FOLDER" =~ "$EXPRESSION" ]]; then
18-
MATCHED_DIR="$CURRENT_FOLDER"
19-
CURRENT_FOLDER=$(dirname "$CURRENT_FOLDER")
20-
else
21-
MATCHING=false
22-
fi
23-
done
24-
if [ -n "$MATCHED_DIR" ]; then
25-
cd "$MATCHED_DIR"
26-
return 0
27-
else
28-
echo "No Match." >&2
29-
return 1
30-
fi
31-
}
2+
function upto() { cd ${PWD%%${PWD#*/*([^/])$1*/}}; }
323

334
# complete upto
345
_upto () {

0 commit comments

Comments
 (0)