mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-21 05:53:22 -07:00
Allow select-screen-profiles to not run interactively
This commit is contained in:
parent
271bbddc81
commit
e7db8eb470
2 changed files with 135 additions and 50 deletions
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -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
|
||||||
|
|
|
@ -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,56 +48,106 @@ if [ -e "$HOME/.screenrc-profile" ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Prompt the user to choose among the available profiles
|
profiles=$(ls $PROFILE_DIR)
|
||||||
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
|
prompt() {
|
||||||
for x in $profiles; do
|
# Prompt the user to choose among the available profiles
|
||||||
i=`expr $i + 1`
|
echo
|
||||||
if [ $i -eq $selected ]; then
|
echo `gettext "Select a screen profile: "`
|
||||||
if [ ! -e "$HOME/.screenrc" ]; then
|
i=0
|
||||||
# If the user doesn't have a .screenrc, seed one
|
|
||||||
echo "source ~/.screenrc-profile" > "$HOME/.screenrc"
|
for x in $profiles; do
|
||||||
else
|
i=$(expr $i + 1)
|
||||||
# If the user does have a .screenrc, see if it has the
|
desc=" "
|
||||||
# source line
|
if [ $x = "ubuntu.screenrc" ]; then
|
||||||
if ! grep -qs "source $HOME/.screenrc-profile" "$HOME/.screenrc"; then
|
desc="<---- ` gettext 'recommended'`"
|
||||||
# And if it's missing the source line, add it
|
simple=$i
|
||||||
# to the top
|
fi
|
||||||
tmp=`mktemp "$HOME/.screenrc.XXXXXX"`
|
echo " $i. $x\t\t$desc"
|
||||||
echo "source $HOME/.screenrc-profile" > "$tmp"
|
done
|
||||||
cat "$HOME/.screenrc" >> "$tmp"
|
echo
|
||||||
mv -f "$tmp" "$HOME/.screenrc"
|
selected=x
|
||||||
fi
|
while /bin/true; do
|
||||||
fi
|
if [ -z "$selected" -a ! -z "$simple" ]; then
|
||||||
rm -f "$HOME/.screenrc-profile"
|
selected="$simple"
|
||||||
ln -s "$PROFILE_DIR/$x" "$HOME/.screenrc-profile"
|
elif ! test $selected -gt 0 2>/dev/null; then
|
||||||
fi
|
read -p "`gettext 'Choose: '` 1-$i [$simple]: " -r selected
|
||||||
done
|
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
|
exit 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue