SOFTELメモ Developer's blog

会社概要 ブログ 調査依頼 採用情報 ...
てるてる動画

【linux】bashの補完がもっと効くようにする

問題

bash があまり親切でなくて、例えば systemctl コマンドの引数が補完されなかったりします。

もうちょっと親切に補完が聞くようにできるでしょうか。

答え

bash-completion パッケージをインストールする。

yum install bash-completion

systemctl や usemod などのコマンドでオプションの補完が聞くようになる。

対象のコマンド例

CentOS stream 9 の場合

$ ls /usr/share/bash-completion/completions/
2to3                   hcitool               puppetdoc
7z                     hd                    puppetmasterd
7za                    hddtemp               puppetqd
a2x                    _hexdump              puppetrun
abook                  hexdump               pv
aclocal                hid2hci               pvchange
aclocal-1.10           host                  pvcreate
aclocal-1.11           hostname              pvdisplay
aclocal-1.12           hostnamectl           pvmove
aclocal-1.13           hping                 pvremove
aclocal-1.14           hping2                pvs
aclocal-1.15           hping3                pvscan
aclocal-1.16           htop                  pwck
acpi                   htpasswd              pwd
_adb                   hunspell              pwdx
add_members            _hwclock              pwgen
addpart                hwclock               pxz
alias                  iceweasel             pycodestyle
alpine                 iconv                 pydoc
alternatives           id                    pydoc3
animate                identify              pydocstyle
ant                    idn                   pyflakes
apache2ctl             ifdown                pylint
appdata-validate       ifquery               pylint-2
apropos                ifstat                pylint-3
apt-build              ifstatus              pypy
apt-cache              iftop                 pypy3
apt-get                ifup                  py.test
aptitude               import                pytest
aptitude-curses        influx                py.test-2
arch                   info                  pytest-2
arm-koji               inject                py.test-3
arp                    inotifywait           pytest-3
arping                 inotifywatch          python
arpspoof               insmod                python2
asciidoc               insmod.static         python2.7
asciidoc.py            installpkg            python3
aspell                 interdiff             python3.3
autoconf               invoke-rc.d           python3.4
autoheader             _ionice               python3.5
automake               ionice                python3.6
automake-1.10          ip                    python3.7
automake-1.11          ipcalc                python3.8
automake-1.12          ipcmk                 pyvenv
automake-1.13          ipcrm                 pyvenv-3.4
automake-1.14          ipcs                  pyvenv-3.5
automake-1.15          iperf                 pyvenv-3.6
automake-1.16          iperf3                pyvenv-3.7
autoreconf             ipmitool              pyvenv-3.8
autorpm                ipsec                 qdbus
autoscan               iptables              qemu
autossh                ipv6calc              qemu-kvm
autoupdate             irqtop                qemu-system-i386
avctrl                 iscsiadm              qemu-system-x86_64
badblocks              isort                 qrunner
bind                   isosize               querybts
bk                     isql                  quota
blkdiscard             iwconfig              quotacheck
blkid                  iwlist                quotaoff
blkzone                iwpriv                quotaon
blockdev               iwspy                 radvdump
bmake                  jar                   ralsh
brctl                  jarsigner             rcs
bsdtar                 java                  rcsdiff
btdownloadcurses.py    javac                 rct
btdownloadgui.py       javadoc               rdesktop
btdownloadheadless.py  javaws                rdict
bts                    journalctl            readprofile
busctl                 jpegoptim             remove_members
bzip2                  jps                   removepkg
c++                    jq                    rename
_cal                   jshint                _renice
cal                    jsonschema            renice
cancel                 json_xs               _repomanage
cardctl                k3b                   reportbug
carton                 kcov                  repquota
cc                     kernel-install        _reptyr
ccache                 kill                  resizepart
ccze                   killall               resolvconf
cdrecord               kldload               rev
cfagent                kldunload             rfcomm
cfdisk                 kmod                  _rfkill
cfrun                  koji                  rfkill
chage                  kplayer               rhsmcertd
change_pw              ktutil                rhsm-debug
chcpu                  l2ping                ri
check_db               larch                 rlog
check_perms            last                  rmlist
checksec               lastlog               rmmod
_chfn                  lbzip2                route
chgrp                  ldapadd               rpcdebug
chkconfig              ldapcompare           rpm
chmem                  ldapdelete            rpm2targz
chmod                  ldapmodify            rpm2tgz
chown                  ldapmodrdn            rpm2txz
chpasswd               ldappasswd            rpmbuild
chrome                 ldapsearch            rpmbuild-md5
chromium               ldapvi                rpmcheck
chromium-browser       ldapwhoami            rrdtool
chronyc                ldattach              rsync
chrpath                lftp                  _rtcwake
chrt                   lftpget               rtcwake
_chsh                  lilo                  _runuser
ci                     links                 runuser
ciptool                links2                s390-koji
civclient              lintian               sbcl
civserver              lintian-info          sbcl-mt
cksfv                  lisp                  sbopkg
cleanarch              list_admins           scp
clisp                  list_lists            screen
clone_member           list_members          script
clzip                  list_owners           scriptlive
co                     localectl             scriptreplay
col                    locale-gen            scrub
colcrt                 logger                sdptool
colormake              loginctl              secret-tool
colrm                  _look                 semanage
column                 look                  setarch
compare                losetup               setpriv
compgen                lpq                   setquota
complete               lpr                   setsebool
composite              lrzip                 setsid
config_list            lsblk                 setterm
configure              lscpu                 sfdisk
conjure                lsinitrd              sftp
convert                lsipc                 sh
coredumpctl            lsirq                 shellcheck
cpan2dist              lslocks               sidedoor
cpio                   lslogins              sitecopy
cppcheck               lsmem                 slackpkg
cpupower               lsns                  slapt-get
createdb               lsof                  slapt-src
createuser             lsscsi                slogin
crontab                lsusb                 smartctl
cryptsetup             lua                   smbcacls
ctrlaltdel             luac                  smbclient
curl                   luseradd              smbcquotas
cvs                    luserdel              smbget
cvsps                  lusermod              smbpasswd
dcop                   lvchange              smbtar
dd                     lvcreate              smbtree
declare                lvdisplay             snownews
deja-dup               lvextend              sparc-koji
delpart                lvm                   spovray
desktop-file-validate  lvmdiskscan           sqlite3
devlink                lvreduce              ss
dfutool                lvremove              ssh
dhclient               lvrename              ssh-add
dict                   lvresize              ssh-copy-id
display                lvs                   sshfs
_dmesg                 lvscan                ssh-keygen
dmesg                  lz4                   sshmitm
dmypy                  lz4c                  sshow
dnf                    lzip                  star
dnssec-keygen          lzma                  strace
dnsspoof               lzop                  stream
dot                    macof                 strings
dpkg                   mailmanctl            _su
dpkg-deb               mailsnarf             su
dpkg-query             make                  subscription-manager
dpkg-reconfigure       makepkg               sudo
dpkg-source            man                   sudoedit
dracut                 mc                    svcadm
dropdb                 mcookie               svk
dropuser               mcrypt                _svn
dselect                mdadm                 _svnadmin
dsniff                 mdecrypt              _svnlook
dumpdb                 mdtool                swaplabel
dumpe2fs               medusa                swapoff
e2freefrag             mencoder              swapon
e2label                mesg                  synclient
ebtables               micropython           sync_members
ecryptfs-migrate-home  mii-diag              sysbench
edquota                mii-tool              sysctl
_eject                 minicom               systemctl
eject                  mkfs                  systemd-analyze
eog                    mkfs.cramfs           systemd-cat
ether-wake             mkfs.minix            systemd-cgls
etherwake              mkinitrd              systemd-cgtop
ethtool                mkisofs               systemd-delta
evince                 mkswap                systemd-detect-virt
explodepkg             mktemp                systemd-id128
export                 mmsitepass            systemd-path
f77                    _mock                 systemd-run
f95                    modinfo               tar
faillog                modprobe              taskset
fallocate              _modules              tc
fbgs                   mogrify               tcpdump
fbi                    monodevelop           tcpkill
fdformat               montage               tcpnice
fdisk                  more                  tightvncviewer
feh                    _mount                timedatectl
file                   _mount.linux          timeout
filebucket             mountpoint            tipc
filefrag               mozilla-firefox       tox
file-roller            mplayer               tracepath
filesnarf              mplayer2              tracepath6
fincore                mr                    trust
find                   msgsnarf              tshark
findfs                 msynctool             tsig-keygen
find_member            mtx                   tune2fs
findmnt                munindoc              tuned-adm
fio                    munin-node-configure  typeset
firefox                munin-run             uclampset
firewall-cmd           munin-update          _udevadm
flake8                 mussh                 udevadm
flock                  mutt                  ul
freebsd-update         muttng                ulimit
freeciv                mypy                  _umount
freeciv-gtk2           mysql                 _umount.linux
freeciv-gtk3           mysqladmin            unace
freeciv-sdl            namei                 unpack200
freeciv-server         nc                    unrar
freeciv-xaw            ncal                  unshare
fsck                   ncftp                 unshunt
fsck.cramfs            nethogs               update-alternatives
fsck.minix             _newgrp               update-rc.d
fsfreeze               newlist               upgradepkg
fstrim                 newusers              urlsnarf
function               ngrep                 useradd
fusermount             nmap                  userdel
g++                    _nmcli                usermod
g4                     nmcli                 utmpdump
g++-5                  nproc                 uuidgen
g++-6                  nsenter               uuidparse
g++-7                  nslookup              valgrind
g77                    nsupdate              vgcfgbackup
g++-8                  ntpdate               vgcfgrestore
g95                    oggdec                vgchange
gapplication           op                    vgck
gcc                    openssl               vgconvert
gcc-5                  opera                 vgcreate
gcc-6                  optipng               vgdisplay
gcc-7                  p11-kit               vgexport
gcc-8                  p4                    vgextend
gccgo                  pack200               vgimport
gccgo-5                partx                 vgmerge
gccgo-6                passwd                vgmknodes
gccgo-7                patch                 vgreduce
gccgo-8                pbzip2                vgremove
gcj                    pccardctl             vgrename
gcl                    pdftotext             vgs
gdb                    pdlzip                vgscan
gdbus                  perl                  vgsplit
genaliases             perlcritic            vigr
gendiff                perldoc               vipw
genisoimage            perltidy              vmstat
geoiplookup            pgrep                 vncviewer
geoiplookup6           phing                 vpnc
getconf                pidof                 wall
getent                 pigz                  watch
getopt                 pine                  wdctl
gfortran               pinfo                 webmitm
gfortran-5             ping                  wget
gfortran-6             ping6                 whatis
gfortran-7             pivot_root            whereis
gfortran-8             pkgadd                wine
gio                    pkg-config            wine-development
git                    pkg_deinstall         wine-stable
gitk                   pkg_delete            wipefs
gkrellm                pkg-get               withlist
gkrellm2               pkg_info              wodim
gm                     pkgrm                 wol
gmake                  pkgtool               _write
gmplayer               pkgutil               write
gnatmake               pkill                 wsimport
gnokii                 plague-client         wtf
gnome-mplayer          plzip                 wvdial
gnome-screenshot       pmake                 xdg-mime
gnumake                pm-hibernate          xdg-settings
google-chrome          pm-is-supported       xfreerdp
google-chrome-stable   pm-powersave          xgamma
gpasswd                pm-suspend            xhost
gpc                    pm-suspend-hybrid     _xm
gpg                    pngfix                xmllint
gpg2                   portinstall           xmlwf
gpgv                   portsnap              xmms
gpgv2                  portupgrade           xmodmap
gphoto2                postalias             xpovray
gprof                  postcat               xrandr
groupadd               postconf              xrdb
groupdel               postfix               xsltproc
groupmems              postmap               xvfb-run
groupmod               postsuper             xvnc4viewer
growisofs              povray                xxd
grpck                  ppc-koji              xz
grub                   prelink               xzdec
gsettings              printenv              ypcat
gssdp-discover         prlimit               ypmatch
gtar                   protoc                _yum
gzip                   psql                  yum-arch
hardlink               puppet                zopfli
hciattach              puppetca              zopflipng
hciconfig              puppetd               zramctl

関連するメモ

コメント