Skip to content

Commit a84ada0

Browse files
author
Oliver Weiler
committed
chore: Match parent name exactly
1 parent aa085ff commit a84ada0

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,10 @@ autoload -U +X bashcompinit && bashcompinit
5959

6060
## Usage
6161

62-
TBD
62+
Type `up` followed by pressing the tab key twice to get a list of parent directory names.
63+
64+
```sh
65+
up <tab><tab>
66+
```
67+
68+
Type `up`

completion/bash/up

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ _up() {
55
local -r pwd_without_leading_slash=${PWD:1}
66

77
local basenames=()
8-
while IFS= read -r -d/; do
9-
basenames+=("$REPLY")
10-
done <<<"$pwd_without_leading_slash"
8+
while IFS= read -r -d/; do
9+
basenames+=("$REPLY")
10+
done <<<"$pwd_without_leading_slash"
1111

1212
[[ $PWD != / ]] && basenames+=(/)
1313

completion/bash/up.bats

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ assert_contains() {
2626
}
2727

2828
@test '_up should not autocomplete the current directory name when given no arguments' {
29-
mkdir -p "${BATS_TEST_TMPDIR}"/src/main/java
30-
cd "${BATS_TEST_TMPDIR}"/src/main/java
29+
mkdir -p "${BATS_TEST_TMPDIR}"/src/main/java
30+
cd "${BATS_TEST_TMPDIR}"/src/main/java
3131

32-
COMP_WORDS=(up)
33-
COMP_CWORD=1
34-
_up
32+
COMP_WORDS=(up)
33+
COMP_CWORD=1
34+
_up
3535

36-
! assert_contains java "${COMPREPLY[@]}"
36+
! assert_contains java "${COMPREPLY[@]}"
3737
}
3838

3939
@test '_up should autocomplete the parent directory name' {

up

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ up() {
55
[[ $1 == / ]] && cd / && return
66

77
# shellcheck disable=SC2164
8-
cd "${PWD%"${PWD##*/"$1"}"}"
8+
cd "${PWD%"${PWD##*/"$1"/}"}"
99
}

up.bats

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load up
1111
[[ $PWD == "${BATS_TEST_TMPDIR}/src/main" ]]
1212
}
1313

14-
@test 'up should jump to the parent directory ending on the given name' {
14+
@test 'up should jump to the parent directory with the given name' {
1515
local -r path=${BATS_TEST_TMPDIR}/src/main/java
1616
mkdir -p "$path"
1717
cd "$path"
@@ -48,3 +48,13 @@ load up
4848

4949
[[ $PWD == "${BATS_TEST_TMPDIR}/com/git hub" ]]
5050
}
51+
52+
@test 'up should jump to the parent directory with the exact given name' {
53+
local -r path=${BATS_TEST_TMPDIR}/java/build/libs/java-0.0.1-SNAPSHOT
54+
mkdir -p "$path"
55+
cd "$path"
56+
57+
up java
58+
59+
[[ $PWD == "${BATS_TEST_TMPDIR}/java" ]]
60+
}

0 commit comments

Comments
 (0)