bashには[TAB]キーで補完機能がありますが、その補完機能を拡張する方法です。
老眼SEは歳を重ねるとともにコマンドも忘れがちになり、この機能は重宝しています。
検証環境
・CentOS Linux release 7.6.1810 (Core)
・Kernel 3.10.0-957.27.2.el7.x86_64
- インストール
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
[root@centos7 ~]# yum info bash-completion Available Packages Name : bash-completion Arch : noarch Epoch : 1 Version : 2.1 Release : 6.el7 Size : 85 k Repo : base/7/x86_64 Summary : Programmable completion for Bash URL : http://bash-completion.alioth.debian.org/ License : GPLv2+ Description : bash-completion is a collection of shell functions that take advantage : of the programmable completion feature of bash. [root@centos7 ~]# yum -y install bash-completion Resolving Dependencies --> Running transaction check ---> Package bash-completion.noarch 1:2.1-6.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================================== Package Arch Version Repository Size ====================================================================================== Installing: bash-completion noarch 1:2.1-6.el7 base 85 k Transaction Summary ====================================================================================== Install 1 Package Total download size: 85 k Installed size: 259 k Downloading packages: bash-completion-2.1-6.el7.noarch.rpm | 85 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 1:bash-completion-2.1-6.el7.noarch 1/1 Verifying : 1:bash-completion-2.1-6.el7.noarch 1/1 Installed: bash-completion.noarch 1:2.1-6.el7 Complete! [root@centos7 ~]# rpmquery --list bash-completion /etc/bash_completion.d /etc/bash_completion.d/redefine_filedir /etc/profile.d/bash_completion.sh /usr/share/bash-completion /usr/share/bash-completion/bash_completion /usr/share/bash-completion/completions /usr/share/bash-completion/completions/bzip2 /usr/share/bash-completion/completions/chage /usr/share/bash-completion/completions/chgrp /usr/share/bash-completion/completions/chown /usr/share/bash-completion/completions/chpasswd /usr/share/bash-completion/completions/cpio /usr/share/bash-completion/completions/curl /usr/share/bash-completion/completions/find /usr/share/bash-completion/completions/groupadd /usr/share/bash-completion/completions/groupdel /usr/share/bash-completion/completions/groupmod /usr/share/bash-completion/completions/gzip /usr/share/bash-completion/completions/ip /usr/share/bash-completion/completions/iptables /usr/share/bash-completion/completions/lvchange /usr/share/bash-completion/completions/lvcreate /usr/share/bash-completion/completions/lvdisplay /usr/share/bash-completion/completions/lvextend /usr/share/bash-completion/completions/lvm /usr/share/bash-completion/completions/lvmdiskscan /usr/share/bash-completion/completions/lvreduce /usr/share/bash-completion/completions/lvremove /usr/share/bash-completion/completions/lvrename /usr/share/bash-completion/completions/lvresize /usr/share/bash-completion/completions/lvs /usr/share/bash-completion/completions/lvscan /usr/share/bash-completion/completions/mdadm /usr/share/bash-completion/completions/mount /usr/share/bash-completion/completions/passwd /usr/share/bash-completion/completions/ping /usr/share/bash-completion/completions/pvchange /usr/share/bash-completion/completions/pvcreate /usr/share/bash-completion/completions/pvdisplay /usr/share/bash-completion/completions/pvmove /usr/share/bash-completion/completions/pvremove /usr/share/bash-completion/completions/pvs /usr/share/bash-completion/completions/pvscan /usr/share/bash-completion/completions/quota /usr/share/bash-completion/completions/quotacheck /usr/share/bash-completion/completions/quotaoff /usr/share/bash-completion/completions/quotaon /usr/share/bash-completion/completions/repquota /usr/share/bash-completion/completions/setquota /usr/share/bash-completion/completions/ssh /usr/share/bash-completion/completions/sudo /usr/share/bash-completion/completions/tcpdump /usr/share/bash-completion/completions/umount /usr/share/bash-completion/completions/useradd /usr/share/bash-completion/completions/userdel /usr/share/bash-completion/completions/usermod /usr/share/bash-completion/completions/vgcfgbackup /usr/share/bash-completion/completions/vgcfgrestore /usr/share/bash-completion/completions/vgchange /usr/share/bash-completion/completions/vgck /usr/share/bash-completion/completions/vgconvert /usr/share/bash-completion/completions/vgcreate /usr/share/bash-completion/completions/vgdisplay /usr/share/bash-completion/completions/vgexport /usr/share/bash-completion/completions/vgextend /usr/share/bash-completion/completions/vgimport /usr/share/bash-completion/completions/vgmerge /usr/share/bash-completion/completions/vgmknodes /usr/share/bash-completion/completions/vgreduce /usr/share/bash-completion/completions/vgremove /usr/share/bash-completion/completions/vgrename /usr/share/bash-completion/completions/vgs /usr/share/bash-completion/completions/vgscan /usr/share/bash-completion/completions/vgsplit /usr/share/bash-completion/completions/wget /usr/share/bash-completion/completions/xz /usr/share/bash-completion/helpers /usr/share/bash-completion/helpers/perl /usr/share/doc/bash-completion-2.1 /usr/share/doc/bash-completion-2.1/AUTHORS /usr/share/doc/bash-completion-2.1/CHANGES /usr/share/doc/bash-completion-2.1/CHANGES.package.old /usr/share/doc/bash-completion-2.1/COPYING /usr/share/doc/bash-completion-2.1/README /usr/share/pkgconfig/bash-completion.pc |
どうもbash-completionをインストールする前にすでに幾つかの定義ファイルはインストールされていました。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
[root@centos7 ~]# ll /usr/share/bash-completion/* -rw-r--r-- 1 root root 520 3月 14 19:37 addpart -rw-r--r-- 1 root root 651 3月 14 19:37 blkdiscard -rw-r--r-- 1 root root 1510 3月 14 19:37 blkid -rw-r--r-- 1 root root 761 3月 14 19:37 blockdev -rw-r--r-- 1 root root 1836 7月 31 17:15 bootctl -rw-r--r-- 1 root root 7716 7月 31 17:15 busctl -rw-r--r-- 1 root root 404 3月 14 19:37 cal -rw-r--r-- 1 root root 736 3月 14 19:37 cfdisk -rw-r--r-- 1 root root 1206 3月 14 19:37 chcpu -rw-r--r-- 1 root root 445 3月 14 19:37 chfn -rw-r--r-- 1 root root 800 3月 14 19:37 chrt -rw-r--r-- 1 root root 506 3月 14 19:37 chsh -rw-r--r-- 1 root root 460 3月 14 19:37 col -rw-r--r-- 1 root root 484 3月 14 19:37 colcrt -rw-r--r-- 1 root root 509 3月 14 19:37 colrm -rw-r--r-- 1 root root 725 3月 14 19:37 column -rw-r--r-- 1 root root 3419 7月 31 17:15 coredumpctl -rw-r--r-- 1 root root 335 3月 14 19:37 ctrlaltdel -rw-r--r-- 1 root root 649 3月 14 19:37 delpart -rw-r--r-- 1 root root 1056 3月 14 19:37 dmesg -rw-r--r-- 1 root root 3584 11月 3 2018 dracut -rw-r--r-- 1 root root 1192 3月 14 19:37 eject -rw-r--r-- 1 root root 593 3月 14 19:37 fallocate -rw-r--r-- 1 root root 414 3月 14 19:37 fdformat -rw-r--r-- 1 root root 1071 3月 14 19:37 fdisk -rw-r--r-- 1 root root 2839 3月 14 19:37 findmnt -rw-r--r-- 1 root root 10389 10月 31 2018 firewall-cmd -rw-r--r-- 1 root root 860 3月 14 19:37 flock -rw-r--r-- 1 root root 789 3月 14 19:37 fsck -rw-r--r-- 1 root root 508 3月 14 19:37 fsck.cramfs -rw-r--r-- 1 root root 403 3月 14 19:37 fsck.minix -rw-r--r-- 1 root root 524 3月 14 19:37 fsfreeze -rw-r--r-- 1 root root 626 3月 14 19:37 fstrim -rw-r--r-- 1 root root 1389 10月 22 2016 gapplication -rw-r--r-- 1 root root 935 10月 22 2016 gdbus -rw-r--r-- 1 root root 815 3月 14 19:37 getopt -rw-r--r-- 1 root root 11681 1月 30 2019 grub -rw-r--r-- 1 root root 2829 1月 9 2018 gsettings -rw-r--r-- 1 root root 659 3月 14 19:37 hexdump -rw-r--r-- 1 root root 2213 7月 31 17:15 hostnamectl -rw-r--r-- 1 root root 937 3月 14 19:37 hwclock -rw-r--r-- 1 root root 837 3月 14 19:37 ionice -rw-r--r-- 1 root root 1423 3月 14 19:37 ipcrm -rw-r--r-- 1 root root 514 3月 14 19:37 ipcs -rw-r--r-- 1 root root 426 3月 14 19:37 isosize -rw-r--r-- 1 root root 5533 7月 31 17:15 journalctl -rw-r--r-- 1 root root 1792 7月 31 17:15 kernel-install -rw-r--r-- 1 root root 3235 10月 31 2018 kmod -rw-r--r-- 1 root root 1263 3月 14 19:37 ldattach -rw-r--r-- 1 root root 3436 7月 31 17:15 localectl -rw-r--r-- 1 root root 1159 3月 14 19:37 logger -rw-r--r-- 1 root root 4127 7月 31 17:15 loginctl -rw-r--r-- 1 root root 572 3月 14 19:37 look -rw-r--r-- 1 root root 1504 3月 14 19:37 losetup -rw-r--r-- 1 root root 1476 3月 14 19:37 lsblk -rw-r--r-- 1 root root 829 3月 14 19:37 lscpu -rw-r--r-- 1 root root 2095 11月 3 2018 lsinitrd -rw-r--r-- 1 root root 1002 3月 14 19:37 lslocks -rw-r--r-- 1 root root 3194 7月 31 17:15 machinectl -rw-r--r-- 1 root root 502 3月 14 19:37 mcookie -rw-r--r-- 1 root root 692 3月 14 19:37 mkfs -rw-r--r-- 1 root root 821 3月 14 19:37 mkfs.cramfs -rw-r--r-- 1 root root 716 3月 14 19:37 mkfs.minix -rw-r--r-- 1 root root 765 3月 14 19:37 mkswap -rw-r--r-- 1 root root 528 3月 14 19:37 more -rw-r--r-- 1 root root 570 3月 14 19:37 mountpoint -rw-r--r-- 1 root root 500 3月 14 19:37 namei -rw-r--r-- 1 root root 3834 3月 14 19:19 nmcli -rw-r--r-- 1 root root 955 3月 14 19:37 nsenter -rw-r--r-- 1 root root 1100 3月 14 19:37 partx -rw-r--r-- 1 root root 387 3月 14 19:37 pivot_root -rw-r--r-- 1 root root 1188 3月 14 19:37 prlimit -rw-r--r-- 1 root root 482 3月 14 19:37 raw -rw-r--r-- 1 root root 679 3月 14 19:37 readprofile -rw-r--r-- 1 root root 632 3月 14 19:37 rename -rw-r--r-- 1 root root 812 3月 14 19:37 renice -rw-r--r-- 1 root root 691 3月 14 19:37 resizepart -rw-r--r-- 1 root root 432 3月 14 19:37 rev -rw-r--r-- 1 root root 10006 10月 31 2018 rpm -rw-r--r-- 1 root root 841 3月 14 19:37 rtcwake lrwxrwxrwx 1 root root 2 8月 20 14:46 runuser -> su -rw-r--r-- 1 root root 667 3月 14 19:37 script -rw-r--r-- 1 root root 592 3月 14 19:37 scriptreplay -rw-r--r-- 1 root root 775 3月 14 19:37 setarch -rw-r--r-- 1 root root 2015 3月 14 19:37 setpriv -rw-r--r-- 1 root root 433 3月 14 19:37 setsid -rw-r--r-- 1 root root 2297 3月 14 19:37 setterm -rw-r--r-- 1 root root 1448 3月 14 19:37 sfdisk -rw-r--r-- 1 root root 864 3月 14 19:37 su -rw-r--r-- 1 root root 635 3月 14 19:37 swaplabel -rw-r--r-- 1 root root 1349 3月 14 19:37 swapon -rw-r--r-- 1 root root 12590 7月 31 17:15 systemctl -rw-r--r-- 1 root root 3989 7月 31 17:15 systemd-analyze -rw-r--r-- 1 root root 1912 7月 31 17:15 systemd-cat -rw-r--r-- 1 root root 1792 7月 31 17:15 systemd-cgls -rw-r--r-- 1 root root 1354 7月 31 17:15 systemd-cgtop -rw-r--r-- 1 root root 1952 7月 31 17:15 systemd-delta -rw-r--r-- 1 root root 1317 7月 31 17:15 systemd-detect-virt -rw-r--r-- 1 root root 5876 7月 31 17:15 systemd-nspawn -rw-r--r-- 1 root root 3598 7月 31 17:15 systemd-run -rw-r--r-- 1 root root 530 3月 14 19:37 tailf -rw-r--r-- 1 root root 1083 3月 14 19:37 taskset -rw-r--r-- 1 root root 27039 4月 24 23:03 tc -rw-r--r-- 1 root root 2580 7月 31 17:15 timedatectl -rw-r--r-- 1 root root 511 7月 5 2018 tuned-adm -rw-r--r-- 1 root root 3726 7月 31 17:15 udevadm -rw-r--r-- 1 root root 655 3月 14 19:37 ul -rw-r--r-- 1 root root 496 3月 14 19:37 unshare -rw-r--r-- 1 root root 466 3月 14 19:37 utmpdump -rw-r--r-- 1 root root 384 3月 14 19:37 uuidgen -rw-r--r-- 1 root root 1202 3月 14 19:37 wdctl -rw-r--r-- 1 root root 535 3月 14 19:37 whereis -rw-r--r-- 1 root root 760 3月 14 19:37 wipefs -rw-r--r-- 1 root root 494 3月 14 19:37 write -rw-r--r-- 1 root root 11496 11月 5 2018 yum lrwxrwxrwx 1 root root 3 1月 9 2019 yummain.py -> yum -rw-r--r-- 1 root root 1213 3月 14 19:37 zramctl |
bash-completionを導入前は
1 2 3 4 5 6 7 8 |
[root@centos7 ~]# systemctl .bash_history .bash_logout .bash_profile .bashrc .cshrc .pki/ .tcshrc |
でしたが、導入後は
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[root@centos7 ~]# systemctl add-requires hybrid-sleep reload-or-restart add-wants is-active reload-or-try-restart cancel is-enabled rescue cat is-failed reset-failed condreload is-system-running restart condrestart isolate set-default condstop kexec set-environment daemon-reexec kill set-property daemon-reload link show default list-dependencies show-environment delete list-jobs snapshot disable list-sockets start edit list-timers status emergency list-unit-files stop enable list-units suspend exit mask switch-root force-reload poweroff try-restart get-default preset unmask halt reboot unset-environment help reenable hibernate reload |
となりました。systemctlはよく使うコマンドなので、これだけでも助かります。
これでかなりのコマンドが補完できると思いますが、必要なものが無ければさらに下記のサイトなどから追加することもできます。
https://github.com/scop/bash-completion
試しにchronycを追加してみます。
1 2 3 4 5 6 7 |
[root@centos7 ~]# curl -o /etc/bash_completion.d/chronyc https://raw.githubusercontent.com/scop/bash-completion/master/completions/chronyc % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1562 100 1562 0 0 5234 0 --:--:-- --:--:-- --:--:-- 5241 [root@centos7 ~]# complete | grep chronyc complete -F _chronyc chronyc |
追加前
1 2 3 4 5 6 |
[root@centos7 ~]# chronyc .bash_history .bash_logout .bash_profile .bashrc .cshrc |
追加後
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
[root@centos7 ~]# chronyc accheck dump minstratum settime activity exit ntpdata smoothing add help offline smoothtime allow keygen online sources burst local polltarget sourcestats clients makestep quit timeout cmdaccheck manual refresh tracking cmdallow maxdelay rekey trimrtc cmddeny maxdelaydevratio reselect waitsync cyclelogs maxdelayratio reselectdist writertc delete maxpoll retries deny maxupdateskew rtcdata dns minpoll serverstats |