Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # check_unused_bash_completion.sh:
- # Checks unused bash_completion files and moves them into
- # /etc/bash_completion.d/unused/.
- #
- BASH_COMPLETION_DIR=/etc/bash_completion.d
- BASH_COMPLETION_DIR_UNUSED="$BASH_COMPLETION_DIR/unused"
- # This function checks whether we have a given program on the system.
- # No need for bulky functions in memory if we don't.
- #
- have()
- {
- unset -v have
- # Completions for system administrator commands are installed as well in
- # case completion is attempted via `sudo command ...'.
- PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin type $1 &>/dev/null &&
- have="yes"
- }
- if [ ! -d $BASH_COMPLETION_DIR_UNUSED ]; then
- mkdir $BASH_COMPLETION_DIR_UNUSED
- fi
- for i in $(LC_ALL=C command ls "$BASH_COMPLETION_DIR"); do
- unset -v have
- i=$BASH_COMPLETION_DIR/$i
- if [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)|Makefile*) \
- && -f $i && -r $i ]]; then
- for j in $(grep -P '^\(?have' "$i" | grep -o -P '(?<=\bhave )[^ )]+'); do
- have "$j" && break
- done
- if [ "$have" = "yes" ]; then
- echo "$i: used"
- else
- echo "$i: unused"
- mv "$i" $BASH_COMPLETION_DIR_UNUSED
- fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement