Allow select-screen-profiles to not run interactively

This commit is contained in:
Nick Barcet 2008-12-19 15:04:26 +01:00
commit e7db8eb470
2 changed files with 135 additions and 50 deletions

1
debian/changelog vendored
View file

@ -5,6 +5,7 @@ screen-profiles (1.1-0ubuntu1) jaunty; urgency=low
* Added some sensible key bindings * Added some sensible key bindings
* First pot and translation to french * First pot and translation to french
* First try at screen-profile-helper * First try at screen-profile-helper
* Allow select-screen-profile to not run interactively
[ Dustin Kirkland ] [ Dustin Kirkland ]
* created keybindings directory, moved keybindings there * created keybindings directory, moved keybindings there

View file

@ -1,10 +1,44 @@
#!/bin/sh -e #!/bin/sh -e
#
# GNU screen-profiles
# Copyright (C) 2008 Canonical Ltd.
#
# Authors: Dustin Kirklan <dustin.kirkland@ubuntu.com>
# Nick Barcet <nick.barcet@ubuntu.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# To generate localization information, run: # To generate localization information, run:
# xgettext -o - -L Shell select-screen-profile # xgettext -o - -L Shell select-screen-profile
usage () {
cat <<EOT
usage: select-screen-profiles [(-l|--list)][(-h|--help)][(-s|--set) PROFILE]
-l,--list list avaivalable profiles
-s,--set PROFILE set profile
-h,--help this help
Without any parameters, runs interactively.
EOT
}
BASE_DIR="/usr/share/screen-profiles" BASE_DIR="/usr/share/screen-profiles"
PROFILE_DIR="$BASE_DIR/profiles" PROFILE_DIR="$BASE_DIR/profiles"
profile=""
selected=-1
# Ensure that ~/.screenrc-profile is a symbolic link # Ensure that ~/.screenrc-profile is a symbolic link
if [ -e "$HOME/.screenrc-profile" ]; then if [ -e "$HOME/.screenrc-profile" ]; then
@ -14,11 +48,14 @@ if [ -e "$HOME/.screenrc-profile" ]; then
fi fi
fi fi
profiles=$(ls $PROFILE_DIR)
prompt() {
# Prompt the user to choose among the available profiles # Prompt the user to choose among the available profiles
echo echo
echo `gettext "Select a screen profile: "` echo `gettext "Select a screen profile: "`
i=0 i=0
profiles=$(ls $PROFILE_DIR)
for x in $profiles; do for x in $profiles; do
i=$(expr $i + 1) i=$(expr $i + 1)
desc=" " desc=" "
@ -41,11 +78,20 @@ while /bin/true; do
break break
fi fi
done done
}
listprofiles() {
for x in $profiles; do
echo "$x"
done
}
setprofile() {
i=0 i=0
found=0
for x in $profiles; do for x in $profiles; do
i=`expr $i + 1` i=`expr $i + 1`
if [ $i -eq $selected ]; then if [ $i -eq $selected ] || [ "$profile" = $x ] ; then
if [ ! -e "$HOME/.screenrc" ]; then if [ ! -e "$HOME/.screenrc" ]; then
# If the user doesn't have a .screenrc, seed one # If the user doesn't have a .screenrc, seed one
echo "source ~/.screenrc-profile" > "$HOME/.screenrc" echo "source ~/.screenrc-profile" > "$HOME/.screenrc"
@ -63,7 +109,45 @@ for x in $profiles; do
fi fi
rm -f "$HOME/.screenrc-profile" rm -f "$HOME/.screenrc-profile"
ln -s "$PROFILE_DIR/$x" "$HOME/.screenrc-profile" ln -s "$PROFILE_DIR/$x" "$HOME/.screenrc-profile"
found=1
fi fi
done done
if [ $found -eq 0 ]; then
echo "Invalid profile name"
fi
}
if [ $# -eq 0 ]; then
prompt
setprofile
else
TEMP=`getopt -o lhs: --long list,help,set: -- "$@"`
eval set -- "$TEMP"
while true
do
case "$1" in
-s|--set)
profile="$2"
setprofile
shift 2
break
;;
-l|--list)
listprofiles
shift
break
;;
*)
usage()
exit 1
;;
--)
shift
break
;;
esac
done
fi
exit 0 exit 0