User Tools

Site Tools


docs:tips_n_tricks:screen.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
docs:tips_n_tricks:screen.html [25.06.2010 17:05 CEST] peterdocs:tips_n_tricks:screen.html [16.03.2024 00:38 CET] (current) – [Logging and reading logs] peter
Line 2: Line 2:
  
 ===== show current directory or command in window name when using zsh ===== ===== show current directory or command in window name when using zsh =====
 +==== Linux ====
 put this in your ''.zshrc'' put this in your ''.zshrc''
  
Line 11: Line 11:
       precmd () {       precmd () {
               let "len = 54 - ${#DISPLAY}"               let "len = 54 - ${#DISPLAY}"
-              screen -X -S "$PPID" title "$DISPLAY - `pwd|sed -e 's:^.*\(.\{'$len'\}\)$:..\1:g'`"+              screen -X -S "$PPID" title "$DISPLAY - `pwd|sed -e 's:^.*\(.\{'$len'\}\)$:..\1:g'($_my_last_cmd)"
       }       }
       preexec () {       preexec () {
               screen -X -S "$PPID" title "$DISPLAY - running: $1"               screen -X -S "$PPID" title "$DISPLAY - running: $1"
 +              _my_last_cmd="$1"
               # # Maybe $2 or $3 is a better choice - I didn't get the difference yet. You may               # # Maybe $2 or $3 is a better choice - I didn't get the difference yet. You may
               # # analyse this with the statement:               # # analyse this with the statement:
Line 21: Line 22:
       ;;       ;;
   esac   esac
 +
 +==== Mac OS X ====
 +On Mac OS X (maybe on BSD systems in general), screen launches a ''login'' process which then executes the shell. Therefore, the id of the screen session (''$STY'') does not start with the parent processes pid (''$PPID''), but with the parent pid of the parent process. Therefor, you have to
 +use the following lines in your ''.zshrc''
 +  case "`ps -o 'command=' -p $PPID`" in
 +  "login"*"zsh") pppid="`ps -o 'ppid=' -p $PPID|sed -e 's/^ *//g'`" ;;
 +  *)        pppid="XXX" ;;
 +  esac
 +  
 +  case "$STY" in
 +    "")
 +      ;;
 +    "$pppid"*)
 +      eval " 
 +      precmd () {
 +              let \"len = 54 - \$#DISPLAY\"
 +            screen -X -S "$STY" title \"\$DISPLAY - \`pwd|sed -e 's:^.*\(.\{'\$len'\}\)\$:..\1:g'\`\"
 +      }
 +      preexec () {
 +              screen -X -S \"$STY\" title \"\$DISPLAY - running: \$1\"
 +      }
 +  "
 +      ;;
 +  esac
 +
  
 ===== show current directory or command in window name when using bash ===== ===== show current directory or command in window name when using bash =====
Line 44: Line 70:
         PROMPT_COMMAND='precmd'         PROMPT_COMMAND='precmd'
         screentitle() { preexec "$BASH_COMMAND"; }         screentitle() { preexec "$BASH_COMMAND"; }
-        trap screentitle DEBUG+        # # nice try :-/ 
 +        # trap screentitle DEBUG 
 +        on_debug() 
 +        { 
 +          case "$BASH_COMMAND" in 
 +          "$PROMPT_COMMAND") ;; 
 +          *) preexec "$BASH_COMMAND" >> /dev/tty < /dev/null 2>&1 & disown ;; 
 +          esac 
 +        } 
 +        trap on_debug DEBUG
       fi       fi
 +      # as we show user and cwd in screen title, 
 +      # clear hardstatus in screen:
 +      echo -en "\033]0;\007"
       ;;       ;;
   esac   esac
 +
 +This seems to break some Pipe chains. There might be a better approach at [[http://www.twistedmatrix.com/users/glyph/preexec.bash.txt|at twistedmatrix]] where the idea to use "''trap'' ... ''DEBUG''" was stolen from ;-)
 +
 +Actually, I consider this trick dirty and hence both solutions.
 +
 +===== Have a separate history for each screen window =====
 +Put this in your ''.profile'', ''.bashrc'', ''.zshenv'' or whatever shell your're using:
 +
 +  [ -n "$WINDOW" ] && HISTFILE="${HISTFILE:-~/.screen_history}.${WINDOW}"
  
 ===== sample .screenrc file ===== ===== sample .screenrc file =====
  
-  #remove some stupid / dangerous key bindings +<code screen .screenrc> 
-  bind ^k +#remove some stupid / dangerous key bindings 
-  bind ^\ +bind ^k 
-  bind k +bind ^\ 
-  startup_message off +bind k 
-  vbell on +# # don't lock screen accidently - use if you don't know the accounts 
-  vbell_msg " Klingeling! " +# # password (e.g. when access is managed by ssh keys) 
-  bindkey -k kb stuff ^? +# bind x 
-  defscrollback 500 +# bind ^x 
-   +startup_message off 
-  caption always +vbell on 
-  caption string "%?%F%{.c.}%?%3n %t%? [%h]%?" +vbell_msg " Klingeling! " 
-  # caption string "%?%F%{.c.}%?%3n %?[%h]%:%t%?" +bindkey -k kb stuff ^? 
-  windowlist string  "%3n %%?[%h]%?" +# Enable cycling backward throug regions in Putty by C-a,Shift+TAB 
-  hardstatus on +bindkey -t "^A^[[Z" focus prev 
-  hardstatus alwayslastline +# Make C-a C-a work smooth again 
-  msgminwait 0+bindkey -t "^A^A" other 
 + 
 +defscrollback 500 
 + 
 +# make $HOME the base for all relative paths 
 +chdir 
 + 
 +caption always 
 +# # show window title and optional 
 +# # hardware status line text 
 +caption string "%?%F%{.c.}%?%3n %t%? [%h]%?" 
 + 
 +# # show window title if set, else hardware status line text 
 +# windowlist string "%3n %?[%h]%:%t%?" 
 +# windowlist title "Num Name|HW Status" 
 +# # show window title and hardware status line text if set 
 +# windowlist string "%3n %t %?[%h]%?" 
 +# windowlist title "Num Name [HW Status]" 
 +# # Use approximately original windowlist string appended by hardware statusline if set 
 +windowlist string "%3n %t%=%?[%h]    %:%?%f " 
 +windowlist title "Num Name%=[HW Status] Flags" 
 +# # show clock in caption line 
 +# caption    string "%?%F%{.b.}%H: %?%3n%? [%h]%: %t%?%=| %c:%s 
 +# Higlight active window, show hold and escape-key state 
 +caption    string "%?%F%{.bw}%?%H: %3n%?%E %{.rw}~a~%{-}%?%?%P %{.wb}~HOLD~%{-}%?%? [%h]%: %t%?%-11=| %c:%s 
 + 
 +hardstatus on 
 +hardstatus alwayslastline 
 +msgminwait 0 
 + 
 +logfile .screenlog/screen.%S.%n.%Y-%m-%d.%0c.log 
 + 
 +zombie xr onerror 
 +# If you're using bash (won't hurt otherwise) 
 +setenv PROMPT_COMMAND 'screen -p "$WINDOW" -X title "$PWD"' 
 +</code> 
 +===== Logging and reading logs ===== 
 +<code screenrc .screenrc> 
 +
 +chdir 
 +logfile screenlog/screen.%S.%n.%Y-%m-%d.%0c.log 
 +
 +</code> 
 + 
 +  col < ~/screenlog/screen.pts-0.www.14.2021-09-06.09:28.log | less 
 + 
 +__References__: 
 +  * [[https://superuser.com/questions/236930/how-to-clean-up-output-of-linux-script-command|How to clean up output of linux 'script' command]] 
 +===== Starting root shell in new screen with non-default shell =====
  
 +  screen -t root sudo ZDOTDIR=$HOME -i /bin/zsh -
  
 +  screen -t root sudo su - -c "ZDOTDIR=$HOME exec zsh"
docs/tips_n_tricks/screen.html.1277478334.txt.gz · Last modified: 25.06.2010 17:05 CEST by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki