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
* First pot and translation to french
* First try at screen-profile-helper
* Allow select-screen-profile to not run interactively
[ Dustin Kirkland ]
* created keybindings directory, moved keybindings there

View file

@ -1,10 +1,44 @@
#!/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:
# 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"
PROFILE_DIR="$BASE_DIR/profiles"
profile=""
selected=-1
# Ensure that ~/.screenrc-profile is a symbolic link
if [ -e "$HOME/.screenrc-profile" ]; then
@ -14,56 +48,106 @@ if [ -e "$HOME/.screenrc-profile" ]; then
fi
fi
# Prompt the user to choose among the available profiles
echo
echo `gettext "Select a screen profile: "`
i=0
profiles=$(ls $PROFILE_DIR)
for x in $profiles; do
i=$(expr $i + 1)
desc=" "
if [ $x = "ubuntu.screenrc" ]; then
desc="<---- ` gettext 'recommended'`"
simple=$i
fi
echo " $i. $x\t\t$desc"
done
echo
selected=x
while /bin/true; do
if [ -z "$selected" -a ! -z "$simple" ]; then
selected="$simple"
elif ! test $selected -gt 0 2>/dev/null; then
read -p "`gettext 'Choose: '` 1-$i [$simple]: " -r selected
elif ! test $selected -le $i 2>/dev/null; then
read -p "`gettext 'Choose: '` 1-$i [$simple]: " -r selected
else
break
fi
done
i=0
for x in $profiles; do
i=`expr $i + 1`
if [ $i -eq $selected ]; then
if [ ! -e "$HOME/.screenrc" ]; then
# If the user doesn't have a .screenrc, seed one
echo "source ~/.screenrc-profile" > "$HOME/.screenrc"
else
# If the user does have a .screenrc, see if it has the
# source line
if ! grep -qs "source $HOME/.screenrc-profile" "$HOME/.screenrc"; then
# And if it's missing the source line, add it
# to the top
tmp=`mktemp "$HOME/.screenrc.XXXXXX"`
echo "source $HOME/.screenrc-profile" > "$tmp"
cat "$HOME/.screenrc" >> "$tmp"
mv -f "$tmp" "$HOME/.screenrc"
fi
fi
rm -f "$HOME/.screenrc-profile"
ln -s "$PROFILE_DIR/$x" "$HOME/.screenrc-profile"
fi
done
prompt() {
# Prompt the user to choose among the available profiles
echo
echo `gettext "Select a screen profile: "`
i=0
for x in $profiles; do
i=$(expr $i + 1)
desc=" "
if [ $x = "ubuntu.screenrc" ]; then
desc="<---- ` gettext 'recommended'`"
simple=$i
fi
echo " $i. $x\t\t$desc"
done
echo
selected=x
while /bin/true; do
if [ -z "$selected" -a ! -z "$simple" ]; then
selected="$simple"
elif ! test $selected -gt 0 2>/dev/null; then
read -p "`gettext 'Choose: '` 1-$i [$simple]: " -r selected
elif ! test $selected -le $i 2>/dev/null; then
read -p "`gettext 'Choose: '` 1-$i [$simple]: " -r selected
else
break
fi
done
}
listprofiles() {
for x in $profiles; do
echo "$x"
done
}
setprofile() {
i=0
found=0
for x in $profiles; do
i=`expr $i + 1`
if [ $i -eq $selected ] || [ "$profile" = $x ] ; then
if [ ! -e "$HOME/.screenrc" ]; then
# If the user doesn't have a .screenrc, seed one
echo "source ~/.screenrc-profile" > "$HOME/.screenrc"
else
# If the user does have a .screenrc, see if it has the
# source line
if ! grep -qs "source $HOME/.screenrc-profile" "$HOME/.screenrc"; then
# And if it's missing the source line, add it
# to the top
tmp=`mktemp "$HOME/.screenrc.XXXXXX"`
echo "source $HOME/.screenrc-profile" > "$tmp"
cat "$HOME/.screenrc" >> "$tmp"
mv -f "$tmp" "$HOME/.screenrc"
fi
fi
rm -f "$HOME/.screenrc-profile"
ln -s "$PROFILE_DIR/$x" "$HOME/.screenrc-profile"
found=1
fi
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