Skip to content

Commit 4fc5c89

Browse files
committed
fix(xdg-mime): trap and cd issues
1 parent f722a8b commit 4fc5c89

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

completions/xdg-mime

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
_xdg_mime_mimetype()
44
{
55
local d i
6+
local -a arr
67
for d in /usr/share/mime /usr/local/share/mime; do
7-
command cd $d 2>/dev/null || continue
8-
trap "command cd - &>/dev/null" RETURN
9-
_filedir xml
10-
for i in ${!COMPREPLY[*]}; do
11-
# packages/ is not a MIME type dir
12-
[[ ${COMPREPLY[i]} != packages* ]] || unset -v "COMPREPLY[i]"
8+
arr=($(
9+
command cd "$d" 2>/dev/null || exit 1
10+
compgen -f -o plusdirs -X "!*.xml" -- "$cur"
11+
)) || continue
12+
for i in ${!arr[*]}; do
13+
case ${arr[i]} in
14+
packages*) unset -v "arr[i]" ;; # not a MIME type dir
15+
*.xml) arr[i]=${arr[i]%.xml} ;;
16+
*/*) ;;
17+
*) arr[i]+=/ ;;
18+
esac
1319
done
14-
COMPREPLY=("${COMPREPLY[@]%.xml}")
15-
return
20+
COMPREPLY+=("${arr[@]}")
1621
done
22+
[[ $COMPREPLY != */ ]] || compopt -o nospace
1723
}
1824

1925
_xdg_mime()

test/t/test_xdg_mime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33

4-
@pytest.mark.bashcomp(cmd="xdg-mime", ignore_env=r"^[+-](OLD)?PWD=")
4+
@pytest.mark.bashcomp(cmd="xdg-mime")
55
class TestXdgMime:
66
@pytest.mark.complete("xdg-mime ")
77
def test_1(self, completion):

0 commit comments

Comments
 (0)