Skip to content

completions: invoke "cd" as "builtin cd" #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions completions/_mount.linux
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ _mount()
;;
-L)
COMPREPLY=($(
cd "/dev/disk/by-label/" 2>/dev/null || return
command cd "/dev/disk/by-label/" 2>/dev/null || return
compgen -f -- "$cur"
))
return
;;
-U)
COMPREPLY=($(
cd "/dev/disk/by-uuid/" 2>/dev/null || return
command cd "/dev/disk/by-uuid/" 2>/dev/null || return
compgen -f -- "$cur"
))
return
Expand Down
2 changes: 1 addition & 1 deletion completions/_umount.linux
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ _linux_fstab()
local i
for i in ${!COMPREPLY[*]}; do
[[ ${COMPREPLY[i]} == "$realcur"* ]] &&
COMPREPLY+=($(cd "$dircur" 2>/dev/null &&
COMPREPLY+=($(command cd -- "$dircur" 2>/dev/null &&
compgen -f -d -P "$dircur" \
-X "!${COMPREPLY[i]##"$dirrealcur"}" -- "$basecur"))
done
Expand Down
4 changes: 2 additions & 2 deletions completions/feh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ _feh()
fi
local font_path
# font_path="$(imlib2-config --prefix 2>/dev/null)/share/imlib2/data/fonts"
# COMPREPLY=( $(cd "$font_path" 2>/dev/null; compgen -f \
# COMPREPLY=( $(command cd -- "$font_path" 2>/dev/null; compgen -f \
# -X "!*.@([tT][tT][fF])" -S / -- "$cur") )
for ((i = ${#words[@]} - 1; i > 0; i--)); do
if [[ ${words[i]} == -@(C|-fontpath) ]]; then
font_path="${words[i + 1]}"
COMPREPLY+=($(
cd "$font_path" 2>/dev/null
command cd -- "$font_path" 2>/dev/null
compgen -f \
-X "!*.@([tT][tT][fF])" -S / -- "$cur"
))
Expand Down
2 changes: 1 addition & 1 deletion completions/removepkg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _removepkg()

local root=${ROOT:-/}
COMPREPLY=($(
cd "$root/var/log/packages" 2>/dev/null || return 1
command cd -- "$root/var/log/packages" 2>/dev/null || return 1
compgen -f -- "$cur"
))
} &&
Expand Down
2 changes: 1 addition & 1 deletion completions/sbopkg
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ _sbopkg()
$REPO_ROOT/$REPO_NAME/$REPO_BRANCH/SLACKBUILDS.TXT
)
$(
cd $QUEUEDIR
command cd -- $QUEUEDIR
compgen -f -X "!*.sqf" -- "$cur"
))
} &&
Expand Down
4 changes: 2 additions & 2 deletions completions/slackpkg
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ _slackpkg()
install-template | remove-template)
if [[ -e $confdir/templates ]]; then
COMPREPLY=($(
cd "$confdir/templates"
command cd -- "$confdir/templates"
compgen -f -X "!*.template" -- "$cur"
))
COMPREPLY=(${COMPREPLY[@]%.template})
Expand All @@ -75,7 +75,7 @@ _slackpkg()
COMPREPLY+=($(compgen -W 'a ap d e f k kde kdei l n t tcl x
xap xfce y' -- "$cur"))
COMPREPLY+=($(
cd /var/log/packages
command cd /var/log/packages
compgen -f -- "$cur"
))
return
Expand Down
2 changes: 1 addition & 1 deletion completions/slapt-get
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ _slapt_get()
;;
ins) # --remove|--filelist
COMPREPLY=($(
cd /var/log/packages
command cd /var/log/packages
compgen -f -- "$cur"
))
return
Expand Down
4 changes: 2 additions & 2 deletions test/runLint
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ gitgrep $cmdstart'[ef]grep\b' \
# TODO: $ in sed subexpression used as an anchor (POSIX BRE optional, not in
# Solaris/FreeBSD)

gitgrep '(?<!command)'$cmdstart'(grep|ls|sed)(\s|$)' \
'invoke grep, ls, and sed through "command", e.g. "command grep"'
gitgrep '(?<!command)'$cmdstart'(grep|ls|sed|cd)(\s|$)' \
'invoke grep, ls, sed, and cd through "command", e.g. "command grep"'

gitgrep '<<<' 'herestrings use temp files, use some other way'

Expand Down
6 changes: 4 additions & 2 deletions test/t/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ def _restore_env(self):
# variables because "cd" affects "OLDPWD".
if self.cwd:
self._unprotect_variable("OLDPWD")
assert_bash_exec(self.bash, "cd %s" % shlex.quote(str(self.cwd)))
assert_bash_exec(
self.bash, "command cd -- %s" % shlex.quote(str(self.cwd))
)
self._protect_variable("OLDPWD")
self.cwd = None

Expand All @@ -505,7 +507,7 @@ def _restore_env(self):
def chdir(self, path: str):
self._save_cwd()
self._unprotect_variable("OLDPWD")
assert_bash_exec(self.bash, "cd %s" % shlex.quote(path))
assert_bash_exec(self.bash, "command cd -- %s" % shlex.quote(path))
self._protect_variable("OLDPWD")

def shopt(self, name: str, value: bool):
Expand Down