diff --git a/debian/changelog b/debian/changelog index dd0b906c..ca2d3d3a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -9,7 +9,16 @@ screen-profiles (1.2) UNRELEASED; urgency=low [Nicolas Valcárcel] * Spanish translations - -- Dustin Kirkland Tue, 06 Jan 2009 15:32:06 -0600 + [ Nicolas Barcet ] + * 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 + * screen-profile-helper allows to install screen by default + * Now uses python-newt instead of python-dialog + * Add framework for useful windows creation + + -- Dustin Kirkland Tue, 06 Jan 2009 17:47:00 -0600 screen-profiles (1.1-0ubuntu1) jaunty; urgency=low diff --git a/debian/control b/debian/control index 832a919a..8e73cd01 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Vcs-Bzr: http://bazaar.launchpad.net/~kirkland/screen-profiles/main Package: screen-profiles Architecture: all -Depends: debconf (>= 0.5) | debconf-2.0, screen, gettext-base, debianutils +Depends: debconf (>= 0.5) | debconf-2.0, screen, gettext-base, python, python-newt Recommends: update-notifier-common Suggests: bc Description: a set of useful profiles and a profile-switcher for GNU screen diff --git a/debian/install b/debian/install index 0a6579c5..f6c7ad19 100644 --- a/debian/install +++ b/debian/install @@ -7,4 +7,8 @@ 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/common usr/share/screen-profiles/windows select-screen-profile usr/bin +screen-profiles-helper usr/bin +screen-install usr/share/screen-profiles/ +screen-launcher usr/share/screen-profiles/ diff --git a/doc/help.txt b/doc/help.txt index 20b9539c..aeda4586 100644 --- a/doc/help.txt +++ b/doc/help.txt @@ -1,13 +1,10 @@ - ********************************************** - ** Welcome to the screen powered terminal ** - ********************************************** Screen is a powerful program that allows your terminal session to have multiple windows and retain context between multiple logins. This version of screen is configured with a task bar at the bottom of the window that shows system status, pending updates, and which window you are currently viewing. -Common mappings* (where C- means ctrl): +Common mappings (where C- means ctrl): ------------------------------------------------------------------------ C-PgUp/Shift-Tab Goto next window | F1 Basic help (this) C-PgDown Goto previous window | F2 Advanced help @@ -18,6 +15,3 @@ C-g Esc Use scrollback (Esc exits) | F6 Close current window Use 'screen -r' to reattach to a detached screen. Complete help on screen can be obtained using the 'man screen' command. Please note that screen is configured to remap the escape prefix from ctrl-A to ctrl-G. - -* These mappings are known to work with xterm compatible terminals (eg - gnome-terminal), but may need to be adjusted for your environment. diff --git a/keybindings/common b/keybindings/common index 2d5c569c..7be678c5 100644 --- a/keybindings/common +++ b/keybindings/common @@ -37,9 +37,13 @@ bindkey -k k4 process n # F4 | Create new window bindkey -k k6 kill # F6 | Close window # Maps for help -bindkey -k k1 screen -t help 0 less /usr/share/doc/screen-profiles/help.txt # F1 | Basic help (this) +bindkey -k k1 screen -t help 0 screen-profiles-helper # 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 6a0da013..c2562c10 100644 --- a/profiles/common +++ b/profiles/common @@ -34,9 +34,8 @@ hardstatus alwayslastline termcapinfo xterm ti@:te@ defscrollback 10000 -# Default windows -screen -t bash 1 -screen -t welcome 0 /usr/bin/sensible-pager /usr/share/doc/screen-profiles/help.txt - # Default keybindings source /usr/share/screen-profiles/keybindings/common + +# Default windows +source /usr/share/screen-profiles/windows/common diff --git a/screen-install b/screen-install new file mode 100755 index 00000000..f8c82812 --- /dev/null +++ b/screen-install @@ -0,0 +1,55 @@ +#!/bin/bash +# +# GNU screen-profiles-helper +# Copyright (C) 2008 Canonical Ltd. +# +# Authors: 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. + + +LAUNCHER="$HOME/.screen-launcher" +BASHRC="$HOME/.bashrc" + +# We have to make sure screen is called last +pos=$(( $(grep -ns "source $LAUNCHER" "$BASHRC" | sed 's/:.*$//' | head -1) )) + +do=0 +if [ $pos -gt 0 ]; then + if [ $pos -lt $(( $(wc -l "$BASHRC" | sed "s/ .*$//") -2)) ]; then + # We have to reposition the line at the end + # First remove it + sed -ibak '/screen-launcher/d' "$BASHRC" + do=1 + fi +else + do=1 +fi + +# Add it at the end +if [ $do -eq 1 ]; then + echo "source $LAUNCHER" >> "$BASHRC" +fi + +# Ensure that ~/.screen-launcher is a symbolic link +if [ -e "$HOME/.screen-launcher" ]; then + if [ ! -L "$HOME/.screen-launcher" ]; then + echo `gettext 'Error:'` $HOME/.screen-launcher `gettext ' file exists, but is not a symlink'` + exit 1 + fi +else + ln -s /usr/share/screen-profiles/screen-launcher "$HOME/.screen-launcher" +fi + diff --git a/screen-launcher b/screen-launcher new file mode 100755 index 00000000..fac5a269 --- /dev/null +++ b/screen-launcher @@ -0,0 +1,29 @@ +#!/bin/bash +# +# GNU screen-profiles-helper +# Copyright (C) 2008 Canonical Ltd. +# +# Authors: 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. + + +# Verify that we are correctly installed +/bin/bash /usr/share/screen-profiles/screen-install + +if [ "$TERM" != "screen" ]; then + screen -xRR + logout +fi diff --git a/screen-profiles-helper b/screen-profiles-helper new file mode 100755 index 00000000..857734c9 --- /dev/null +++ b/screen-profiles-helper @@ -0,0 +1,198 @@ +#! /usr/bin/env python +# +# GNU screen-profiles-helper +# Copyright (C) 2008 Canonical Ltd. +# +# Authors: 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. + +import sys, os, os.path, time, string, commands +from snack import * + +# Command presets for windows creation +cmd=( ("System activity", "top", "top"), + ("System log", "log", "watch -n 10 tail -n 5 /var/log/syslog /var/log/auth.log /var/log/dmesg"), + ("Disk and ram usage", "mem", 'watch -n 30 "df -h; echo ""; free -mt"')) + + +def ioctl_GWINSZ(fd): #### TABULATION FUNCTIONS + try: ### Discover terminal width + import fcntl, termios, struct, os + cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234')) + except: + return None + return cr + +def terminal_size(): ### decide on *some* terminal size + cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2) # try open fds + if not cr: # ...then ctty + try: + fd = os.open(os.ctermid(), os.O_RDONLY) + cr = ioctl_GWINSZ(fd) + os.close(fd) + except: + pass + if not cr: # env vars or finally defaults + try: + cr = (env['LINES'], env['COLUMNS']) + except: + cr = (25, 80) + return int(cr[1]-5), int(cr[0]-5) # reverse rows, cols + +def menu(screen, size): + li = Listbox(height = 4, width = 60, returnExit = 1) + li.append("Help", 1) + li.append("Change screen profile", 2) + li.append("Create new window(s)", 3) + li.append("Install screen by default at login", 4) + bb = ButtonBar(screen, (("Ok", "ok"), ("Exit", "exit")), compact = 1) + + g = GridForm(screen, "GNU Screen Profiles Menu", 1, 2) + g.add(li, 0, 0, padding=(4,2,4,2)) + g.add(bb, 0, 1, padding=(1,1,0,0)) + + if bb.buttonPressed(g.runOnce()) == "exit": + return 0 + else: + return li.current() + +def messagebox(screen, width, height, title, text, \ + scroll=0, \ + buttons=(("Ok", "ok"),("Cancel", "cancel")) ): + + t = Textbox(width, height, text, scroll=scroll ) + bb = ButtonBar(screen, buttons, compact = 1) + g = GridForm(screen, title, 1, 2) + g.add(t, 0, 0, padding=(0,0,0,0)) + g.add(bb, 0, 1, padding=(1,1,0,0)) + + return bb.buttonPressed(g.runOnce()) + +def help(screen, size): + f=file('/usr/share/doc/screen-profiles/help.txt') + text=f.read() + f.close() + + button = messagebox(screen, 76, 19, "GNU Screen Profiles Help", text, \ + scroll=1, buttons=(("Menu", "menu"), ("Exit", "exit")) ) + + if button == "exit": + return 0 + else: + return 100 + +def profile(screen, size): + li = Listbox(height = 6, width = 60, returnExit = 1) + + for choice in commands.getoutput('select-screen-profile -l').splitlines(): + if choice.startswith("ubuntu"): + li.append(choice+" <-- recommended", choice) + li.setCurrent(choice) + else: + li.append(choice, choice) + + bb = ButtonBar(screen, (("Apply", "apply"), ("Cancel", "cancel")), compact = 1) + + g = GridForm(screen, "Which profile would you like to use?", 1, 2) + g.add(li, 0, 0, padding=(4,2,4,2)) + g.add(bb, 0, 1, padding=(1,1,0,0)) + + if bb.buttonPressed(g.runOnce()) != "cancel": + commands.getoutput('select-screen-profile --set %s' % li.current()) + button = messagebox(screen, 60, 2, "Message", "Press F5 to apply the new profile", \ + buttons=(("Ok","ok"), ("Exit", "exit")) ) + if button == "exit": + return 0 + + return 100 + +def newwindow(screen, size): + title=Entry(8, text="bash", returnExit=1) + titlel=Label("Title: ") + command=Entry(20, text="/bin/bash", returnExit=1) + commandl=Label("Command: ") + + rl=Label("Presets: ") + if len(cmd) > 10: + scroll=1 + size=10 + else: + scroll=0 + size = len(cmd) + + r=CheckboxTree(size, scroll=scroll) + count=0 + for cur in cmd: + r.append(cur[0], count) + count=count+1 + + bb = ButtonBar(screen, (("Create", "create"), ("Cancel", "cancel")), compact = 1) + g = GridForm(screen, "Create new window(s):", 2, 4 ) + g.add(titlel, 0, 0, anchorLeft=1,padding=(4,1,0,1)) + g.add(title, 1, 0, anchorLeft=1) + g.add(commandl, 0, 1, anchorLeft=1, anchorTop=1,padding=(4,0,0,1)) + g.add(command, 1, 1, anchorLeft=1) + g.add(rl, 0, 2, anchorLeft=1,padding=(4,0,0,1)) + g.add(r, 1, 2) + g.add(bb, 1, 3, padding=(4,1,0,0)) + + if bb.buttonPressed(g.runOnce()) != "cancel": + sel=r.getSelection() + if sel: + for s in sel: + commands.getoutput('screen -t %s %s' % (cmd[s][1], cmd[s][2]) ) + else: + commands.getoutput('screen -t %s %s' % (title.value(), command.value()) ) + + return 100 + +def install(screen, size): + out = commands.getoutput("bash /usr/share/screen-profiles/screen-install") + if out == "": + out = "Screen will be launched automatically next time you login." + + button = messagebox(screen, 60, 2, "Message", out, \ + buttons=(("Ok","ok"), ("Exit", "exit")) ) + if button == "exit": + return 0 + + return 100 + +def main(): + """This is the main loop of our screen helper. + """ + size = terminal_size() + screen = SnackScreen() + screen.drawRootText(1,0,"== GNU Screen Profiles Helper ==") + screen.pushHelpLine("/ between elements | Validates") + tag = help(screen, size) + + while tag > 0 : + tag = menu(screen, size) + if tag == 1: + tag = help(screen, size) + elif tag == 2: + tag = profile(screen, size) + elif tag == 3: + tag = newwindow(screen, size) + elif tag == 4: + tag = install(screen, size) + + screen.finish() + sys.exit(0) + + +if __name__ == "__main__": main() diff --git a/select-screen-profile b/select-screen-profile index 0792fc38..a81d2acc 100755 --- a/select-screen-profile +++ b/select-screen-profile @@ -1,69 +1,160 @@ #!/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 + SELECTED="$selected" +} + +setprofile() { + # Apply a profile by name or index + selected="$SELECTED" + i=0 + found=0 + profiles=$(listprofiles) + for x in $profiles; do + i=`expr $i + 1` + if [ "$i" = "$selected" -o "$x" = "$selected" ]; then + if [ ! -e "$HOME/.screenrc" ]; then + # If the user doesn't have a .screenrc, seed one + echo "source $HOME/.screenrc-profile" > "$HOME/.screenrc" + else + # If the user does have a .screenrc, see if it has the + # 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 + fi + rm -f "$HOME/.screenrc-profile" + ln -s "$PROFILE_DIR/$x" "$HOME/.screenrc-profile" + found=1 + break + fi + done + if [ $found -eq 0 ]; then + echo "Invalid profile" + 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 -# 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 $HOME/.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 - exit 0 diff --git a/windows/common b/windows/common new file mode 100644 index 00000000..d55f559a --- /dev/null +++ b/windows/common @@ -0,0 +1,3 @@ +# Default windows +#screen -t welcome 0 screen-profiles-helper +screen -t shell 1