Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[config] screen, hardstatus bar, zsh, term
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index French
View previous topic :: View next topic  
Author Message
polytan
Guru
Guru


Joined: 29 Jul 2004
Posts: 370
Location: Cambridge - UK

PostPosted: Fri Nov 16, 2007 11:49 pm    Post subject: [config] screen, hardstatus bar, zsh, term Reply with quote

Bonjour,

Je ne vous ai pas contacté depuis longtemps, mais voici un nouveau challenge :D :

Je me suis mis à utiliser screen et c'est très pratique.

Cependant, dès que je mets des infos dans mon .screenrc, typiquement une barre de status, je perds les informations usuelles affichées dans la barre de titre.

Un peu comme quand on met a jour une machine avec emerge -uvDNa world et que dans la berre de titre ca affiche :
Quote:
emerging (23 of 346) net/dhcp-3.1.2


Je tente donc de récupérer cette information.

J'utilise Terminal, mais c'est pareil avec xterm.

Je ne comprends pas pourquoi ca ne s'affiche plus, mais une barre de statut est tellement pratique quand on se promene dans un screen qu'on peut difficilement faire sans.

Savez-vous comment afficher la barre de statut ET le titre dynamique dans la fenêtre du term utilisé ?

A travers mes promenade en quete du graal, je suis tombé sur zsh qui a l'air bien mieu que bash pour faire ce genre de truc.

Cependant, repasser a bash m'est tout a fait possible (meme si je viens juste de finir de paramétrer mon zshrc). Tout ce que je veux, c'est un term fonctionnel avec un shell et aussi avec screen.

Voici mon .zshrc :
Code:
# CREDITS
# Some of this file is mine <slarti@gentoo.org>, some is take from
# spider's <spider@gentoo.org> zshrc, and some from the zshwiki.org.
# Some bash functions are nicked from ciaranm's <ciaranm@gentoo.org>
# bashrc
# Je fut aidé par tomaw / I was helped by tomaw

# README
# * Remember to change the stuff specific to me! It's all at the top of
#   this file.
# * You can obviously only get the most out of this file if you take the
#   time to read through the comments. Of course, you can still see
#   zsh's superiority by simply plugging this file in and using it.

# Things from dev.gentoo.org/~ciaranm/configs/bashrc -- thanks Ciaran!
if [[ "${TERM}" == "rxvt-unicode" ]] ; then
    export TERMTYPE="256"
elif [[ "${TERM}" != "dumb" ]] ; then
    export TERMTYPE="16"
else
    export TERMTYPE=""
    export NOCOLOR="true"
fi

if [[ "${TERM}" == "rxvt-unicode" ]] && \
    [[ ! -f /usr/share/terminfo/r/rxvt-unicode ]] && \
    [[ ! -f ~/.terminfo/r/rxvt-unicode ]] ; then
    export TERM=rxvt
fi

if [[ -n "${PATH/*$HOME\/bin:*}" ]] ; then
    export PATH="$HOME/bin:$PATH"
fi

if [[ -n "${PATH/*\/usr\/local\/bin:*}" ]] ; then
    export PATH="/usr/local/bin:$PATH"
fi

if [[ -f /usr/bin/less ]] ; then
    export PAGER=less
    export LESS="--ignore-case --long-prompt"
fi
if [[ -f /usr/bin/vimpager ]] ; then
    export PAGER=vimpager
    export MANPAGER=vimmanpager
fi
alias page=$PAGER

#if [ -z $VG_VIEWGLOB_ACTIVE ] && [ $DISPLAY ] ; then
#    exec viewglob
#fi

# END LOCAL

# Change word boundary characters. Nabbed from
# http://zshwiki.org/KeyBindings.

# by default: export WORDCHARS='*?_-.[]~=/&;!#$%^(){}<>'
# we take out the slash, period, angle brackets, dash here.
export WORDCHARS='*?_-[]~=&;!#$%^(){}'

# Follow GNU LS_COLORS for completion menus
zmodload -i zsh/complist
eval $(dircolors -b /home/maxbilh/.dir_colors)
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*:*:kill:*' list-colors '=%*=01;31'

# Load the completion system
autoload -U compinit; compinit

# Very powerful version of mv implemented in zsh. The main feature I
# know of it that seperates it from the standard mv is that it saves you
# time by being able to use patterns which are expanded into positional
# parameters. So:
#
# slarti@pohl % zmv (*)foo ${1}bar
#
# On a series of files like onefoo, twofoo, threefoo, fivefoo would be
# renamed to onebar twobar threebar fourbar.
#
# Although that's nifty enough, I suspect there are other features I
# don't know about yet...
#
# Read $fpath/zmv for some more basic examples of usage, and also use
# run-help on it :)
autoload -U zmv

# Command line calculator written in zsh, with a complete history
# mechanism and other shell features.
autoload -U zcalc

# Like xargs, but instead of reading lines of arguments from standard input,
# it takes them from the command line. This is possible/useful because,
# especially with recursive glob operators, zsh often can construct a command
# line for a shell function that is longer than can be accepted by an external
# command. This is what's often referred to as the "shitty Linux exec limit" ;)
# The limitation is on the number of characters or arguments.
#
# slarti@pohl % echo {1..30000}
# zsh: argument list too long: /bin/echo
# zsh: exit 127   /bin/echo {1..30000}
autoload -U zargs

# Yes, we are as bloated as emacs
autoload -U tetris
zle -N tetris
bindkey "^Xt" tetris

# Makes it easy to type URLs as command line arguments. As you type, the
# input character is analyzed and, if it mayn eed quoting, the current
# word is checked for a URI scheme. If one is found and the current word
# is not already quoted, a blackslash is inserted before the input
# caracter.
autoload -U url-quote-magic
zle -N self-insert url-quote-magic

# zed is a tiny command-line editor in pure ZSH; no other shell could do
# this.  zed itself is simple as anything, but it's killer feature for
# me is that it can edit functions on the go with zed -f <funcname> (or
# fned <funcname>. This is useful for me when I'm using and defining
# functions interactively, for example, when I'm working through the
# Portage tree in CVS. It allows me to edit a function on the fly,
# without having to call the last definition back up from the history
# and re-edit that in ZLE. It also indents the function, even if it was
# defined on all one line in the line editor, making it easy as anything
# to edit.
#
# ^X^W to save, ^C to abort.
autoload -U zed

# Incremental completion of a word. After starting this, a list of
# completion choices can be shown after every character you type, which
# can deleted with ^H or delete. Return will accept the current
# completion. Hit tab for normal completion, ^G to get back where you
# came from and ^D to list matches.
autoload -U incremental-complete-word
zle -N incremental-complete-word
bindkey "^Xi" incremental-complete-word

# This function allows you type a file pattern, and see the results of
# the expansion at each step.  When you hit return, they will be
# inserted into the command line.
autoload -U insert-files
zle -N insert-files
bindkey "^Xf" insert-files

# This set of functions implements a sort of magic history searching.
# After predict-on, typing characters causes the editor to look backward
# in the history for the first line beginning with what you have typed so
# far.  After predict-off, editing returns to normal for the line found.
# In fact, you often don't even need to use predict-off, because if the
# line doesn't match something in the history, adding a key performs
# standard completion - though editing in the middle is liable to delete
# the rest of the line.
autoload -U predict-on
zle -N predict-on
zle -N predict-off
bindkey "^X^Z" predict-on
bindkey "^Z" predict-off

# We need to get rid of the old run-help (NOTE: if you source ~/.zshrc
# this will through up a warning about the alias not existing for
# unaliasing. The solution is to form an if construct, with the
# condition that run-help is aliased. I do not know how to do this.
unalias run-help
# Load the new one
autoload -U run-help

# Colours
autoload -U colors; colors

# For those who want the default Gentoo prompt back.
# I used to have this earlier in the file, but it didn't work with
# *just* the gentoo prompt theme. I would investigate, but I'm
# lazy.
autoload -U promptinit; promptinit
prompt gentoo

# _gnu_generic is a completion widget that parses the --help output of
# commands for options. df and feh work fine with it, however options
# are not described.
compdef _gnu_generic feh df

compdef _pkglist ecd emetadataviewer
compdef _useflaglist explainuseflag
compdef _category list_cat
compdef _nothing etc-update dispatch-conf fixpackages

function title {
  if [[ $TERM == "screen" ]]; then
    # Use these two for GNU Screen:
    print -nR $'\033k'$1$'\033'\\\

    print -nR $'\033]0;'$2$'\a'
  elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then
    # Use this one instead for XTerms:
    print -nR $'\033]0;'$*$'\a'
  fi
}

precmd() {
#    [[ -t 1 ]] || return
    case $TERM in
   *xterm*|rxvt*) print -Pn "]2;%n@%m:%~\a"
   ;;
   screen*) print -Pn "\"%n@%m:%~\134"
   ;;
    esac
}

# This sets the window title to the last run command.
preexec() {
#    [[ -t 1 ]] || return
    case $TERM in
   *xterm*|rxvt*)
   print -Pn "]2;$1\a"
   ;;
   screen*)
   print -Pn "\"$1\134"
   ;;
    esac
}


# Pretty menu!
zstyle ':completion:*' menu select=1

# Completion options
zstyle ':completion:*' completer _complete _prefix
zstyle ':completion::prefix-1:*' completer _complete
zstyle ':completion:incremental:*' completer _complete _correct
zstyle ':completion:predict:*' completer _complete

# Completion caching
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ~/.zsh/cache/$HOST

# Expand partial paths
zstyle ':completion:*' expand 'yes'
zstyle ':completion:*' squeeze-slashes 'yes'

# Include non-hidden directories in globbed file completions
# for certain commands
zstyle ':completion::complete:*' '\'

# Use menuselection for pid completion
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always

#  tag-order 'globbed-files directories' all-files
zstyle ':completion::complete:*:tar:directories' file-patterns '*~.*(-/)'

# Don't complete backup files as executables
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~'

# Separate matches into groups
zstyle ':completion:*:matches' group 'yes'

# With commands like rm, it's annoying if you keep getting offered the same
# file multiple times. This fixes it. Also good for cp, et cetera..
zstyle ':completion:*:rm:*' ignore-line yes
zstyle ':completion:*:cp:*' ignore-line yes

# Describe each match group.
zstyle ':completion:*:descriptions' format "%B---- %d%b"

# Messages/warnings format
zstyle ':completion:*:messages' format '%B%U---- %d%u%b'
zstyle ':completion:*:warnings' format '%B%U---- no match for: %d%u%b'

# Describe options in full
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'




HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000

bindkey '[5~' history-search-backward
bindkey '[6~' history-search-forward

autoload zkbd
[[ ! -d ~/.zkbd ]] && mkdir ~/.zkbd
[[ ! -f ~/.zkbd/$TERM-$VENDOR-$OSTYPE ]] && zkbd
source  ~/.zkbd/$TERM-$VENDOR-$OSTYPE
# setup key accordingly
[[ -n "${key[Home]}"    ]]  && bindkey  "${key[Home]}"    beginning-of-line
[[ -n "${key[End]}"     ]]  && bindkey  "${key[End]}"     end-of-line
[[ -n "${key[Insert]}"  ]]  && bindkey  "${key[Insert]}"  overwrite-mode
[[ -n "${key[Delete]}"  ]]  && bindkey  "${key[Delete]}"  delete-char
[[ -n "${key[Up]}"      ]]  && bindkey  "${key[Up]}"      up-line-or-history
[[ -n "${key[Down]}"    ]]  && bindkey  "${key[Down]}"    down-line-or-history
[[ -n "${key[Left]}"    ]]  && bindkey  "${key[Left]}"    backward-char
[[ -n "${key[Right]}"   ]]  && bindkey  "${key[Right]}"   forward-char

alias ls='ls --color=auto'
alias grep='grep --colour=auto'

alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
alias rm='rm -v'
alias cp='cp -v'
alias mv='mv -v'
alias msd='mousepad'


Et enfin, le screenrc :

Code:
defutf8 on
shell /bin/zsh
encoding UTF-8
vbell off
defnonblock 5

hardstatus alwayslastline "%{=}%{g}[ %{W}%H %{g}][%= %{w}%?%-Lw%?%{r}(%{W}%n*%f %t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][ %{B}%D %d/%m%{W}%c:%s %{g}]"

shelltitle '$ |zsh'
idle 3000 lockscreen


Si vous voulez d'autres infos...je suis là :)
_________________
Wait & See

-=( Polytan )=-
Back to top
View user's profile Send private message
Untux
Apprentice
Apprentice


Joined: 10 Apr 2006
Posts: 285

PostPosted: Sat Nov 17, 2007 2:50 pm    Post subject: Reply with quote

Alut. Tout est dans le « %h » ! (Voir man screen, section String Escapes). Mon hardstatus à titre d'exemple :
extrait /etc/screenrc wrote:

hardstatus alwayslastline
hardstatus string '%{= kG}%?%{g}[%h]%?%{g}[%= %{= kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][ %d-%m-%y %c ]'


Edit : Ah, et maintenant que j'y repense, je crois que la fonction suivante est également nécessaire :
Code:

function title {
  if [[ $TERM == "screen" ]]; then
    # Use these two for GNU Screen:
    print -nR $'\033k'$1$'\033'\\\

    print -nR $'\033]0;'$2$'\a'
  elif [[ $TERM == "xterm" || $TERM == "rxvt" ]]; then
    # Use this one instead for XTerms:
    print -nR $'\033]0;'$*$'\a'
  fi
}

... à ajouter à ton ~/.zshrc. Je ne sais plus si c'est indispensable, j'ai la flemme de tester :)

Re-edit : à quoi il faut ajouter (toujours dans ~/.zshrc)
Code:

function precmd {
  title zsh "$PWD"
}
 
function preexec {
  emulate -L zsh
  local -a cmd; cmd=(${(z)1})
  title $cmd[1]:t "$cmd[2,-1]"
}

oualà... j'espère que c'était mon dernier « edit » :?
Back to top
View user's profile Send private message
polytan
Guru
Guru


Joined: 29 Jul 2004
Posts: 370
Location: Cambridge - UK

PostPosted: Sat Nov 17, 2007 4:02 pm    Post subject: Reply with quote

Donc ok, le %h rajoute l'info que je recherche.

Mais comment faire pour qu'elle soit affichée dans la barre de titre, qui est un espace inutilisé en fait :)
_________________
Wait & See

-=( Polytan )=-
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Sat Nov 17, 2007 5:13 pm    Post subject: Reply with quote

regarde les séquences d'échappement de ton terminal, par exemple pour renommer 'une fenètre' de screen, c'est la sequence
^[k

(^[ est *le* caractère d'échappement tu l'obtiens par ESC ( pour le rentrer littérallement tu tapes d'abord ^V )
tu peux également te servir de son code ascii \033 ou même avec \e dans bash
et tu termines une chaine par cette séquence ^[\
pour renommer tu peux donc faire ^[kmontitre^[\ (tu devras peut-être échapper le \ selon l'endroit où tu t'en sers

par exemple dans ton screen lance cat

puis appuie sur: ESC k ceketuveux ESC \ ENTREE

tadaaaa!! ;)


et oui c'est aussi simple que ça :)


Pour les
Code:
emerging (23 of 346) net/dhcp-3.1.2


C'est un hack d'emerge qui utilise la séquence d'échappement de xterm pour
renommer la barre du titre

La dite séquence est quelque chose comme ça: ESC ] 0 ; emergingblahblah ^G

Rien ne t'empèche donc d'utiliser les systèmes de hook d'emerge ou de paludis, pour envoyer la séquence de ton choix, aux moments de ton choix, a ton terminal(screen en l'occurrence) ( et donc changer automatiquement le titre de ta fenètre (visible dans la ligne 'hardstatus))


voili-voilou :)


Je ne le crie haut et fort: screen powaaaaa ;)

[OFF]
J'y pense depuis un moment maintenant, j'ferai un petit 'howto' pour une utilisation (plus) avancée de screen un de ces quatres, car on ne trouve que
des guides pour une utilisation plus ou moins basique, laissant à peine imaginer que screen peut en faire *vraiment* beaucoup (plus). Je ne
prétends cependant toujours pas maitriser screen à fond, sa page de manuel est une/la véritable mine d'information, mais il n'est pas toujours facile
d'en sortir ce que l'on veut...:) Quoiqu'il en soit l'article prend progressivement forme dans ma tête :)
dsl pour le squouattage de topic...
[/OFF]
_________________
The End of the Internet!


Last edited by truc on Sun Nov 18, 2007 9:36 am; edited 4 times in total
Back to top
View user's profile Send private message
CryoGen
Veteran
Veteran


Joined: 11 Feb 2004
Posts: 1426
Location: Bamako - Mali - Afrique

PostPosted: Sat Nov 17, 2007 5:29 pm    Post subject: Reply with quote

Moi je n'utilise screen que dans une session ssh pour pouvoir la fermer sans arrêter mon rtorrent qui tourne dedans XD

J'attends ton article avec impatience :lol:
_________________
- CryoGen` on #gentoofr@irc.freenode.net
- ~amd64 / KDE4
- I'm the bone of my sword...
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index French All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum