From 025b0c11a866c1369a9148754737db73b79204ad Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 28 Feb 2017 02:13:37 +0000 Subject: [PATCH 1/2] Fix bash completion for 'show' command --- data/etc/bash.bashrc | 57 +++++++++++++++++++++++++++++++++ data/etc/bash_completion.d/show | 8 +++++ setup.py | 4 +++ stdeb.cfg | 2 +- 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 data/etc/bash.bashrc create mode 100644 data/etc/bash_completion.d/show diff --git a/data/etc/bash.bashrc b/data/etc/bash.bashrc new file mode 100644 index 0000000000..b531c88a06 --- /dev/null +++ b/data/etc/bash.bashrc @@ -0,0 +1,57 @@ +# System-wide .bashrc file for interactive bash(1) shells. + +# To enable the settings / commands in this file for login shells as well, +# this file has to be sourced in /etc/profile. + +# If not running interactively, don't do anything +[ -z "$PS1" ] && return + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + +# set variable identifying the chroot you work in (used in the prompt below) +if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then + debian_chroot=$(cat /etc/debian_chroot) +fi + +# set a fancy prompt (non-color, overwrite the one in /etc/profile) +PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' + +# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default. +# If this is an xterm set the title to user@host:dir +#case "$TERM" in +#xterm*|rxvt*) +# PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' +# ;; +#*) +# ;; +#esac + +# enable bash completion in interactive shells +if ! shopt -oq posix; then + if [ -f /usr/share/bash-completion/bash_completion ]; then + . /usr/share/bash-completion/bash_completion + elif [ -f /etc/bash_completion ]; then + . /etc/bash_completion + fi +fi + +# if the command-not-found package is installed, use it +if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then + function command_not_found_handle { + # check because c-n-f could've been removed in the meantime + if [ -x /usr/lib/command-not-found ]; then + /usr/lib/command-not-found -- "$1" + return $? + elif [ -x /usr/share/command-not-found/command-not-found ]; then + /usr/share/command-not-found/command-not-found -- "$1" + return $? + else + printf "%s: command not found\n" "$1" >&2 + return 127 + fi + } +fi + + diff --git a/data/etc/bash_completion.d/show b/data/etc/bash_completion.d/show new file mode 100644 index 0000000000..fbab3cd77c --- /dev/null +++ b/data/etc/bash_completion.d/show @@ -0,0 +1,8 @@ +_show_completion() { + COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \ + COMP_CWORD=$COMP_CWORD \ + _SHOW_COMPLETE=complete $1 ) ) + return 0 +} + +complete -F _show_completion -o default show; diff --git a/setup.py b/setup.py index 5ed14a13d0..00a611f915 100644 --- a/setup.py +++ b/setup.py @@ -22,6 +22,10 @@ 'scripts/portstat', 'scripts/sfputil', ], + data_files=[ + ('/etc', ['data/etc/bash.bashrc']), + ('/etc/bash_completion.d', ['data/etc/bash_completion.d/show']) + ], entry_points={ 'console_scripts': [ 'show = sonic_cli.main:cli', diff --git a/stdeb.cfg b/stdeb.cfg index ad9dc4b00d..e74391cb26 100644 --- a/stdeb.cfg +++ b/stdeb.cfg @@ -1,2 +1,2 @@ [DEFAULT] -Depends: psmisc, grub2-common +Depends: psmisc, grub2-common, bash-completion From 0bd7e4a4568cd98b43bed4638a8b9dcf8f5cc8f8 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Wed, 1 Mar 2017 16:49:59 +0000 Subject: [PATCH 2/2] Remove bash.bashrc file from package; will add to sonic-buildimage --- data/etc/bash.bashrc | 57 -------------------------------------------- setup.py | 1 - 2 files changed, 58 deletions(-) delete mode 100644 data/etc/bash.bashrc diff --git a/data/etc/bash.bashrc b/data/etc/bash.bashrc deleted file mode 100644 index b531c88a06..0000000000 --- a/data/etc/bash.bashrc +++ /dev/null @@ -1,57 +0,0 @@ -# System-wide .bashrc file for interactive bash(1) shells. - -# To enable the settings / commands in this file for login shells as well, -# this file has to be sourced in /etc/profile. - -# If not running interactively, don't do anything -[ -z "$PS1" ] && return - -# check the window size after each command and, if necessary, -# update the values of LINES and COLUMNS. -shopt -s checkwinsize - -# set variable identifying the chroot you work in (used in the prompt below) -if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then - debian_chroot=$(cat /etc/debian_chroot) -fi - -# set a fancy prompt (non-color, overwrite the one in /etc/profile) -PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' - -# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default. -# If this is an xterm set the title to user@host:dir -#case "$TERM" in -#xterm*|rxvt*) -# PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"' -# ;; -#*) -# ;; -#esac - -# enable bash completion in interactive shells -if ! shopt -oq posix; then - if [ -f /usr/share/bash-completion/bash_completion ]; then - . /usr/share/bash-completion/bash_completion - elif [ -f /etc/bash_completion ]; then - . /etc/bash_completion - fi -fi - -# if the command-not-found package is installed, use it -if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then - function command_not_found_handle { - # check because c-n-f could've been removed in the meantime - if [ -x /usr/lib/command-not-found ]; then - /usr/lib/command-not-found -- "$1" - return $? - elif [ -x /usr/share/command-not-found/command-not-found ]; then - /usr/share/command-not-found/command-not-found -- "$1" - return $? - else - printf "%s: command not found\n" "$1" >&2 - return 127 - fi - } -fi - - diff --git a/setup.py b/setup.py index 00a611f915..844a17bc3e 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,6 @@ 'scripts/sfputil', ], data_files=[ - ('/etc', ['data/etc/bash.bashrc']), ('/etc/bash_completion.d', ['data/etc/bash_completion.d/show']) ], entry_points={