From 78d0900d2d550398953ca2a10f1cbe0b8bf5d2dc Mon Sep 17 00:00:00 2001 From: Nick Barcet Date: Fri, 19 Dec 2008 18:46:17 +0100 Subject: [PATCH] * screen-profile-helper allows to create new windows * screen-profile-helper allows to select profiles --- debian/changelog | 2 ++ debian/install | 1 + keybindings/common | 4 ++++ profiles/common | 4 ---- screen-profiles-helper.py | 27 +++++++++++++++------ select-screen-profile | 49 ++++++++++++++++++++++++++++----------- windows/default | 3 +++ 7 files changed, 66 insertions(+), 24 deletions(-) create mode 100644 windows/default diff --git a/debian/changelog b/debian/changelog index 59466364..cca97c8a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,8 @@ screen-profiles (1.1-0ubuntu1) jaunty; urgency=low * First pot and translation to french * First try at screen-profile-helper * Allow select-screen-profile to not run interactively + * screen-profile-helper allows to create new windows + * screen-profile-helper allows to select profiles [ Dustin Kirkland ] * created keybindings directory, moved keybindings there diff --git a/debian/install b/debian/install index 06238c27..f506ae65 100644 --- a/debian/install +++ b/debian/install @@ -7,5 +7,6 @@ profiles/common usr/share/screen-profiles/profiles profiles/debian.screenrc usr/share/screen-profiles/profiles profiles/ubuntu.screenrc usr/share/screen-profiles/profiles keybindings/common usr/share/screen-profiles/keybindings +windows/default usr/share/screen-profiles/windows select-screen-profile usr/bin screen-profiles-helper.py usr/share/screen-profiles/ diff --git a/keybindings/common b/keybindings/common index 2d5c569c..f1fe27f9 100644 --- a/keybindings/common +++ b/keybindings/common @@ -40,6 +40,10 @@ bindkey -k k6 kill # F6 | Close window bindkey -k k1 screen -t help 0 less /usr/share/doc/screen-profiles/help.txt # F1 | Basic help (this) bindkey -k k2 help # F2 | Advanced help +# Reload +register r "^g:source $HOME/.screenrc-profile" +bindkey -k k5 process r + # power detach register x "^g^d D" bindkey ^[[3;6~ process x # C-shift-del | Detach and logout diff --git a/profiles/common b/profiles/common index 555502ad..aecf8c9d 100644 --- a/profiles/common +++ b/profiles/common @@ -34,9 +34,5 @@ hardstatus alwayslastline termcapinfo xterm ti@:te@ defscrollback 10000 -# Default windows -screen -t bash 1 -screen -t welcome 0 python /usr/share/screen-profiles/screen-profiles-helper.py - # Default keybindings source /usr/share/screen-profiles/keybindings/common diff --git a/screen-profiles-helper.py b/screen-profiles-helper.py index 0a490957..a7d936ec 100644 --- a/screen-profiles-helper.py +++ b/screen-profiles-helper.py @@ -1,6 +1,6 @@ #! /usr/bin/env python -import sys, os, os.path, time, string, dialog +import sys, os, os.path, time, string, dialog, commands def ioctl_GWINSZ(fd): #### TABULATION FUNCTIONS try: ### Discover terminal width @@ -52,8 +52,8 @@ def menu_demo(d, size): width=size[0], choices=[("1", "Display some basic help"), ("2", "Change screen profile"), - ("3", "Change key bindings"), - ("4", "Launch screen by default") + ("3", "Create a new window"), + ("4", "Install screen by default at login") ]) if handle_exit_code(d, code): break @@ -63,10 +63,23 @@ def help(d, size): d.textbox("/usr/share/doc/screen-profiles/help.txt", width=size[0], height=size[1]) def profile(d): - d.msgbox("This has yet to be implemented") + list = [] + for choice in commands.getoutput('select-screen-profile -l').splitlines(): + if choice.startswith("ubuntu"): + el = (choice, "<-- recommended", 1) + list.append(el) + else: + el = (choice, "", 0) + list.append(el) + (code, tag) = d.radiolist("Which profile would you like to use?", width=65, choices=list) + if code == d.DIALOG_OK: + commands.getoutput('select-screen-profile --set %s' % tag) + d.msgbox("Please press F5 to apply profile") -def key(d): - d.msgbox("This has yet to be implemented") +def newwindow(d): + (code, answer) = d.inputbox("New window name?", init="bash") + if code == d.DIALOG_OK: + commands.getoutput('screen -t %s' % answer) def default(d): d.msgbox("This has yet to be implemented") @@ -90,7 +103,7 @@ def main(): elif tag == "2": profile(d) elif tag == "3": - key(d) + newwindow(d) elif tag == "4": default(d) diff --git a/select-screen-profile b/select-screen-profile index 7692b94e..bfb14018 100755 --- a/select-screen-profile +++ b/select-screen-profile @@ -35,18 +35,28 @@ usage: select-screen-profiles [(-l|--list)][(-h|--help)][(-s|--set) PROFILE] EOT } +# Initialize variables BASE_DIR="/usr/share/screen-profiles" PROFILE_DIR="$BASE_DIR/profiles" +WINDOW_DIR="$BASE_DIR/windows" profile="" selected=-1 # Ensure that ~/.screenrc-profile is a symbolic link if [ -e "$HOME/.screenrc-profile" ]; then - if [ ! -L "$HOME/.screenrc-profile" ]; then - echo `gettext 'Error:'` $HOME/.screenrc-profile `gettext ' file exists, but is not a symlink'` - exit 1 - fi + if [ ! -L "$HOME/.screenrc-profile" ]; then + echo `gettext 'Error:'` $HOME/.screenrc-profile `gettext ' file exists, but is not a symlink'` + exit 1 + fi fi +# Ensure that ~/.screenrc-window is a symbolic link +if [ -e "$HOME/.screenrc-window" ]; then + if [ ! -L "$HOME/.screenrc-window" ]; then + echo `gettext 'Error:'` $HOME/.screenrc-window `gettext ' file exists, but is not a symlink'` + exit 1 + fi +fi + profiles=$(ls $PROFILE_DIR) @@ -81,12 +91,14 @@ prompt() { } listprofiles() { + # Display list of profiles, one per line for x in $profiles; do echo "$x" done } setprofile() { + # Apply a profile by name ($profile) or index ($selected) i=0 found=0 for x in $profiles; do @@ -95,20 +107,31 @@ setprofile() { if [ ! -e "$HOME/.screenrc" ]; then # If the user doesn't have a .screenrc, seed one echo "source ~/.screenrc-profile" > "$HOME/.screenrc" + echo "source ~/.screenrc-window" >> "$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 + # sources lines + 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 + if ! grep -qs "source $HOME/.screenrc-window" "$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-window" > "$tmp" + cat "$HOME/.screenrc" >> "$tmp" + mv -f "$tmp" "$HOME/.screenrc" + fi fi rm -f "$HOME/.screenrc-profile" + rm -f "$HOME/.screenrc-window" ln -s "$PROFILE_DIR/$x" "$HOME/.screenrc-profile" + ln -s "$WINDOW_DIR/default" "$HOME/.screenrc-window" found=1 fi done diff --git a/windows/default b/windows/default new file mode 100644 index 00000000..733692a6 --- /dev/null +++ b/windows/default @@ -0,0 +1,3 @@ +# Default windows +screen -t bash 1 +screen -t welcome 0 python /usr/share/screen-profiles/screen-profiles-helper.py