Skip to content

Commit 1c1b24a

Browse files
committed
refactor: { => _comp_compgen}_tilde with interface changes
1 parent f9c0471 commit 1c1b24a

File tree

11 files changed

+37
-24
lines changed

11 files changed

+37
-24
lines changed

bash_completion

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ _comp_quote_compgen()
850850
#
851851
_comp_compgen_filedir()
852852
{
853-
_tilde "${cur-}" || return
853+
_comp_compgen_tilde && return
854854

855855
local -a toks
856856
local arg=${1-}
@@ -1458,21 +1458,21 @@ _ncpus()
14581458
}
14591459

14601460
# Perform tilde (~) completion
1461-
# @return True (0) if completion needs further processing,
1462-
# False (1) if tilde is followed by a valid username, completions are
1461+
# @return False (1) if completion needs further processing,
1462+
# True (0) if tilde is followed by a valid username, completions are
14631463
# put in COMPREPLY and no further processing is necessary.
1464-
# TODO: rename per API conventions
1465-
_tilde()
1464+
_comp_compgen_tilde()
14661465
{
1467-
if [[ ${1-} == \~* && $1 != */* ]]; then
1466+
if [[ ${cur-} == \~* && $cur != */* ]]; then
14681467
# Try generate ~username completions
1469-
if _comp_compgen -c "${1#\~}" -- -P '~' -u; then
1470-
# 2>/dev/null for direct invocation, e.g. in the _tilde unit test
1468+
if _comp_compgen -c "${cur#\~}" -- -P '~' -u; then
1469+
# 2>/dev/null for direct invocation, e.g. in the
1470+
# _comp_compgen_tilde unit test
14711471
compopt -o filenames 2>/dev/null
1472-
return 1
1472+
return 0
14731473
fi
14741474
fi
1475-
return 0
1475+
return 1
14761476
}
14771477

14781478
# Expand variable starting with tilde (~)
@@ -1519,7 +1519,7 @@ _expand()
15191519
__expand_tilde_by_ref cur
15201520
;;
15211521
~*)
1522-
_tilde "$cur" ||
1522+
_comp_compgen -v COMPREPLY tilde &&
15231523
eval "COMPREPLY[0]=$(printf ~%q "${COMPREPLY[0]#\~}")"
15241524
return ${#COMPREPLY[@]}
15251525
;;
@@ -2556,7 +2556,7 @@ _filedir_xspec()
25562556
local cur prev words cword comp_args
25572557
_comp_initialize -- "$@" || return
25582558
2559-
_tilde "$cur" || return
2559+
_comp_compgen_tilde && return
25602560
25612561
local ret
25622562
_comp_quote_compgen "$cur"

bash_completion.d/000_bash_completion_compat.bash

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,16 @@ _filedir()
264264
_comp_compgen -a filedir "$@"
265265
}
266266

267+
# Perform tilde (~) completion
268+
# @return True (0) if completion needs further processing,
269+
# False (1) if tilde is followed by a valid username, completions are
270+
# put in COMPREPLY and no further processing is necessary.
271+
# @deprecated Use `_comp_compgen -c CUR tilde [-d]`. Note that the exit status
272+
# of `_comp_compgen_tilde` is flipped. It returns 0 when the tilde completions
273+
# are attempted, or otherwise 1.
274+
_tilde()
275+
{
276+
! _comp_compgen -c "$1" tilde
277+
}
278+
267279
# ex: filetype=sh

completions/bzip2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ _comp_cmd_bzip2()
3434
[[ $prev == -*z* ]] && xspec=
3535
fi
3636

37-
_tilde "$cur" || return
37+
_comp_compgen_tilde && return
3838

3939
compopt -o filenames
4040
COMPREPLY=($(compgen -f -X "$xspec" -- "$cur") $(compgen -d -- "$cur"))

completions/gzip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ _comp_cmd_gzip()
3535
[[ $prev == -*f* ]] && xspec=
3636
fi
3737

38-
_tilde "$cur" || return
38+
_comp_compgen_tilde && return
3939

4040
compopt -o filenames
4141
COMPREPLY=($(compgen -f -X "$xspec" -- "$cur")

completions/lrzip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ _comp_cmd_lrzip()
4444
return
4545
fi
4646

47-
_tilde "$cur" || return
47+
_comp_compgen_tilde && return
4848

4949
local IFS=$'\n'
5050
compopt -o filenames

completions/lz4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ _comp_cmd_lz4()
4141
esac
4242
done
4343

44-
_tilde "$cur" || return
44+
_comp_compgen_tilde && return
4545

4646
local IFS=$'\n'
4747
compopt -o filenames

completions/lzma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ _comp_cmd_lzma()
2424
[[ $prev == -*z* ]] && xspec=
2525
fi
2626

27-
_tilde "$cur" || return
27+
_comp_compgen_tilde && return
2828

2929
compopt -o filenames
3030
COMPREPLY=($(compgen -f -X "$xspec" -- "$cur") $(compgen -d -- "$cur"))

completions/lzop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ _comp_cmd_lzop()
5050
;;
5151
esac
5252

53-
_tilde "$cur" || return
53+
_comp_compgen_tilde && return
5454

5555
local IFS=$'\n'
5656
compopt -o filenames

completions/xz

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ _comp_cmd_xz()
4747
return
4848
fi
4949

50-
_tilde "$cur" || return
50+
_comp_compgen_tilde && return
5151

5252
local IFS=$'\n'
5353
compopt -o filenames

completions/zopfli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ _comp_cmd_zopfli()
1818
return
1919
fi
2020

21-
_tilde "$cur" || return
21+
_comp_compgen_tilde && return
2222

2323
local IFS=$'\n' xspec="*.@(gz|t[ag]z)"
2424
compopt -o filenames

0 commit comments

Comments
 (0)