Bash completion functions for pmount and pumount
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
5
down vote
favorite
I found a problem with Debian's Bash-completion for pmount
and pumount
, and intended to send a patch with the bug report - but I got carried away, and ended up completely re-writing the completion functions.
I'd like a review of this before sending my new functions with the bug report.
The original was in /etc/bash_completion.d/pmount
, but the modern approach is to have two files in /usr/share/bash-completion/completions/
to support demand-loading of completion functions. We assume that the _init_completion
is provided as part of this mechanism, to initialize shell variables cur
and prev
more usefully than the usual $2
and $3
(e.g. skipping redirection words).
I've gone to some lengths to find the actual available charsets and filesystem types that can be used, but the hairiest code is in finding the available names for devices (I like to be able to use the symlinks in /dev/disk/by-label/
to ensure I'm using the device/partition I'm expecting, for example).
/usr/share/bash-completion/completions/pmount
_pmount() grep -vxF "$(cut -d' ' /proc/mounts -f1)"))
test "$#devices[@]" -gt 0 &&
complete -F _pmount pmount
/usr/share/bash-completion/completions/pumount
_pumount()
# shellcheck disable=SC2034
local cur prev words cword
_init_completion &&
complete -F _pumount pumount
Some specific questions:
- Should I be checking that commands such as
modinfo
actually exist? Which commands don't need checking? (I believe thatgrep
andcut
are in "Essential" packages, so can be assumed, but I'm less sure aboutreadlink
, for example). - Is it guaranteed that
/media
is the only place to find the mountpoints? - How can I make those long lines wrap nicely without becoming even less clear?
Obviously, any other observations or improvements are invited, too!
bash linux bash-completion
add a comment |Â
up vote
5
down vote
favorite
I found a problem with Debian's Bash-completion for pmount
and pumount
, and intended to send a patch with the bug report - but I got carried away, and ended up completely re-writing the completion functions.
I'd like a review of this before sending my new functions with the bug report.
The original was in /etc/bash_completion.d/pmount
, but the modern approach is to have two files in /usr/share/bash-completion/completions/
to support demand-loading of completion functions. We assume that the _init_completion
is provided as part of this mechanism, to initialize shell variables cur
and prev
more usefully than the usual $2
and $3
(e.g. skipping redirection words).
I've gone to some lengths to find the actual available charsets and filesystem types that can be used, but the hairiest code is in finding the available names for devices (I like to be able to use the symlinks in /dev/disk/by-label/
to ensure I'm using the device/partition I'm expecting, for example).
/usr/share/bash-completion/completions/pmount
_pmount() grep -vxF "$(cut -d' ' /proc/mounts -f1)"))
test "$#devices[@]" -gt 0 &&
complete -F _pmount pmount
/usr/share/bash-completion/completions/pumount
_pumount()
# shellcheck disable=SC2034
local cur prev words cword
_init_completion &&
complete -F _pumount pumount
Some specific questions:
- Should I be checking that commands such as
modinfo
actually exist? Which commands don't need checking? (I believe thatgrep
andcut
are in "Essential" packages, so can be assumed, but I'm less sure aboutreadlink
, for example). - Is it guaranteed that
/media
is the only place to find the mountpoints? - How can I make those long lines wrap nicely without becoming even less clear?
Obviously, any other observations or improvements are invited, too!
bash linux bash-completion
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I found a problem with Debian's Bash-completion for pmount
and pumount
, and intended to send a patch with the bug report - but I got carried away, and ended up completely re-writing the completion functions.
I'd like a review of this before sending my new functions with the bug report.
The original was in /etc/bash_completion.d/pmount
, but the modern approach is to have two files in /usr/share/bash-completion/completions/
to support demand-loading of completion functions. We assume that the _init_completion
is provided as part of this mechanism, to initialize shell variables cur
and prev
more usefully than the usual $2
and $3
(e.g. skipping redirection words).
I've gone to some lengths to find the actual available charsets and filesystem types that can be used, but the hairiest code is in finding the available names for devices (I like to be able to use the symlinks in /dev/disk/by-label/
to ensure I'm using the device/partition I'm expecting, for example).
/usr/share/bash-completion/completions/pmount
_pmount() grep -vxF "$(cut -d' ' /proc/mounts -f1)"))
test "$#devices[@]" -gt 0 &&
complete -F _pmount pmount
/usr/share/bash-completion/completions/pumount
_pumount()
# shellcheck disable=SC2034
local cur prev words cword
_init_completion &&
complete -F _pumount pumount
Some specific questions:
- Should I be checking that commands such as
modinfo
actually exist? Which commands don't need checking? (I believe thatgrep
andcut
are in "Essential" packages, so can be assumed, but I'm less sure aboutreadlink
, for example). - Is it guaranteed that
/media
is the only place to find the mountpoints? - How can I make those long lines wrap nicely without becoming even less clear?
Obviously, any other observations or improvements are invited, too!
bash linux bash-completion
I found a problem with Debian's Bash-completion for pmount
and pumount
, and intended to send a patch with the bug report - but I got carried away, and ended up completely re-writing the completion functions.
I'd like a review of this before sending my new functions with the bug report.
The original was in /etc/bash_completion.d/pmount
, but the modern approach is to have two files in /usr/share/bash-completion/completions/
to support demand-loading of completion functions. We assume that the _init_completion
is provided as part of this mechanism, to initialize shell variables cur
and prev
more usefully than the usual $2
and $3
(e.g. skipping redirection words).
I've gone to some lengths to find the actual available charsets and filesystem types that can be used, but the hairiest code is in finding the available names for devices (I like to be able to use the symlinks in /dev/disk/by-label/
to ensure I'm using the device/partition I'm expecting, for example).
/usr/share/bash-completion/completions/pmount
_pmount() grep -vxF "$(cut -d' ' /proc/mounts -f1)"))
test "$#devices[@]" -gt 0 &&
complete -F _pmount pmount
/usr/share/bash-completion/completions/pumount
_pumount()
# shellcheck disable=SC2034
local cur prev words cword
_init_completion &&
complete -F _pumount pumount
Some specific questions:
- Should I be checking that commands such as
modinfo
actually exist? Which commands don't need checking? (I believe thatgrep
andcut
are in "Essential" packages, so can be assumed, but I'm less sure aboutreadlink
, for example). - Is it guaranteed that
/media
is the only place to find the mountpoints? - How can I make those long lines wrap nicely without becoming even less clear?
Obviously, any other observations or improvements are invited, too!
bash linux bash-completion
edited Apr 3 at 10:23
asked Apr 3 at 8:58
Toby Speight
17.5k13489
17.5k13489
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f191141%2fbash-completion-functions-for-pmount-and-pumount%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password