diff --git a/debian/changelog b/debian/changelog index 1320fb02..59466364 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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 diff --git a/select-screen-profile b/select-screen-profile index 0daf28a5..7692b94e 100755 --- a/select-screen-profile +++ b/select-screen-profile @@ -1,10 +1,44 @@ #!/bin/sh -e +# +# GNU screen-profiles +# Copyright (C) 2008 Canonical Ltd. +# +# Authors: Dustin Kirklan +# Nick Barcet +# +# 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 </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 +profiles=$(ls $PROFILE_DIR) -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