bash-completion: Standardize fsck/mkfs file/device

Some of the fsck and mkfs commands complete differently than the others,
and differently than the desired behavior.[1]  Standardize on completing
with $(lsblk -pnro name):

* fsck: Don't complete completes on all block devices and device links
  under /dev immediately (which is excessive and prone to search
  problems).
* mkfs, mkfs.bfs: Don't complete "/path/to/file" literally.  I assume
  this was copy/pasted from example code, since it does not appear to be
  a valid argument unless it is a valid path, which is rare.
* fsck.cramfs, mkfs, mkfs.bfs, mkfs.cramfs, mkswap: Don't complete on
  all filenames initially.  The desired behavior is to complete
  filenames only if there are no canonical matches.[1]

Note: A subsequent commit will add the desired fallback behavior.

[1]: https://github.com/karelzak/util-linux/issues/842#issuecomment-523450243

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This commit is contained in:
Kevin Locke 2019-09-19 07:27:31 -06:00
parent d978ec31f7
commit 559888c873
6 changed files with 6 additions and 13 deletions

View File

@ -32,8 +32,7 @@ _fsck_module()
return 0
;;
esac
COMPREPLY=( $(compgen -W "$(find -L /dev/ -path /dev/fd -prune \
-o -type b -print 2>/dev/null)" -- $cur) )
COMPREPLY=( $(compgen -W "$(lsblk -pnro name)" -- $cur) )
return 0
}
complete -F _fsck_module fsck

View File

@ -25,9 +25,7 @@ _fsck.cramfs_module()
return 0
;;
esac
local IFS=$'\n'
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
COMPREPLY=( $(compgen -W "$(lsblk -pnro name)" -- $cur) )
return 0
}
complete -F _fsck.cramfs_module fsck.cramfs

View File

@ -21,7 +21,7 @@ _mkfs_module()
return 0
;;
esac
COMPREPLY=( $(compgen -W "$(lsblk -pnro name) /path/to/file" -- $cur) )
COMPREPLY=( $(compgen -W "$(lsblk -pnro name)" -- $cur) )
return 0
}
complete -F _mkfs_module mkfs

View File

@ -24,7 +24,7 @@ _mkfs.bfs_module()
return 0
;;
esac
COMPREPLY=( $(compgen -W "$(lsblk -pnro name) /path/to/file" -- $cur) )
COMPREPLY=( $(compgen -W "$(lsblk -pnro name)" -- $cur) )
return 0
}
complete -F _mkfs.bfs_module mkfs.bfs

View File

@ -36,9 +36,7 @@ _mkfs.cramfs_module()
return 0
;;
esac
local IFS=$'\n'
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
COMPREPLY=( $(compgen -W "$(lsblk -pnro name)" -- $cur) )
return 0
}
complete -F _mkfs.cramfs_module mkfs.cramfs

View File

@ -32,9 +32,7 @@ _mkswap_module()
return 0
;;
esac
local IFS=$'\n'
compopt -o filenames
COMPREPLY=( $(compgen -f -- $cur) )
COMPREPLY=( $(compgen -W "$(lsblk -pnro name)" -- $cur) )
return 0
}
complete -F _mkswap_module mkswap