abclinuxu.cz AbcLinuxu.cz itbiz.cz ITBiz.cz HDmag.cz HDmag.cz abcprace.cz AbcPráce.cz
Inzerujte na AbcPráce.cz od 950 Kč
Rozšířené hledání
×
    včera 23:55 | Nová verze

    Byla vydána nová stabilní verze 24.05 linuxové distribuce NixOS (Wikipedie). Její kódové označení je Uakari. Podrobný přehled novinek v poznámkách k vydání. O balíčky se v NixOS stará správce balíčků Nix.

    Ladislav Hagara | Komentářů: 0
    včera 17:33 | Nová verze

    Byla vydána nová verze 1.48.0 sady nástrojů pro správu síťových připojení NetworkManager. Novinkám se v příspěvku na blogu NetworkManageru věnuje Fernando F. Mancera. Mimo jiné se v nastavení místo mac-address-blacklist nově používá mac-address-denylist.

    Ladislav Hagara | Komentářů: 10
    včera 17:11 | Komunita

    Před 25 lety, 31. května 1999, započal vývoj grafického editoru Krita (Wikipedie). Tenkrát ještě pod názvem KImageShop a později pod názvem Krayon.

    Ladislav Hagara | Komentářů: 3
    včera 12:55 | Nová verze

    Farid Abdelnour se v příspěvku na blogu rozepsal o novinkám v nejnovější verzi 24.05.0 editoru videa Kdenlive (Wikipedie). Ke stažení brzy také na Flathubu.

    Ladislav Hagara | Komentářů: 0
    včera 11:22 | Zajímavý článek

    David Revoy, autor mj. komiksu Pepper&Carrot, se rozepsal o své aktuální grafické pracovní stanici: Debian 12 Bookworm, okenní systém X11, KDE Plasma 5.27, …

    Ladislav Hagara | Komentářů: 9
    30.5. 22:44 | Nová verze

    Wayland (Wikipedie) byl vydán ve verzi 1.23.0. Z novinek lze vypíchnout podporu OpenBSD.

    Ladislav Hagara | Komentářů: 0
    30.5. 21:22 | Zajímavý článek

    Craig Loewen na blogu Microsoftu představil novinky ve Windows Subsystému pro Linux (WSL). Vypíchnout lze GUI aplikaci pro nastavování WSL nebo správu WSL z Dev Home.

    Ladislav Hagara | Komentářů: 0
    30.5. 12:44 | Pozvánky

    V sobotu 1. června lze navštívit Maker Faire Ostrava, festival plný workshopů, interaktivních činností a především nadšených a zvídavých lidí.

    Ladislav Hagara | Komentářů: 0
    30.5. 12:22 | Nová verze

    Webový server Caddy (Wikipedie) s celou řadou zajímavých vlastností byl vydán ve verzi 2.8 (𝕏). Přehled novinek na GitHubu.

    Ladislav Hagara | Komentářů: 14
    29.5. 22:11 | Nová verze

    Byla vydána verze 3.0 (@, 𝕏) svobodného softwaru HAProxy (The Reliable, High Performance TCP/HTTP Load Balancer; Wikipedie) řešícího vysokou dostupnost, vyvažování zátěže a reverzní proxy. Detailní přehled novinek v příspěvku na blogu společnosti HAProxy Technologies.

    Ladislav Hagara | Komentářů: 7
    Rozcestník

    vylepsenie prompt-u a screen hardstatus

    10.1.2010 18:54 | Přečteno: 1464× | Vzhlad | poslední úprava: 10.1.2010 18:53

    K dnesnemu zapisku bude potrebna mala znalost skriptovania v bash (iba k prvej obsahovej casti). Cielom bude vylepsit prompt aby prepinal svoju farebnost podla nazvu emulatoru terminalu a aby obsahoval escape sekvenciu s nazvom prave vykonavaneho programu.

    Najprv mala zmienka o tom co vlastne budeme upravovat:
    When executing interactively, bash  displays  the  primary
    prompt  PS1  when  it  is ready to read a command, and the
    secondary prompt PS2 when it needs more input to  complete
    a  command.   Bash  allows these prompt strings to be cus-
    tomized by inserting a number of backslash-escaped special
    characters that are decoded as follows:
    


    Upravit bude treba subor ~/.bashrc (zmeny sa prejavia lokalne). Najdeme zmienku o PS1 (primary prompt) ktora v povodnom stave v distribucii Debian GNU/Linux (dalej len ako Debian) vyzera napr. takto: #PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '. Nasu cast kodu budeme vkladat az za tuto definiciu. Pokial ste este nerobili ziadne zmeny v .bashrc mozete tam najst aj nasledovny komentar: # set a fancy prompt (non-color, unless we know we "want" color) (stale plati pre Debian). Tento komentar je vyznamovo dolezity, kedze sa dozvedame ze sa jedna o nefarebny prompt. Tomuto je prisposobena aj cast kodu ktoru budeme vkladat.

    Odriadkujeme teda a vlozime nasledovne:
    case "$TERM" in
    xterm*|aterm*|rxvt*|urxvt*)
            . ~/.prompt_xterm
        ;;
    screen*)
            . ~/.prompt_xterm
            PROMPT_COMMAND='echo -ne "\033k\033\\"'
        ;;
           
    *)
        ;;
    esac
    

    Tento kus kodu je vlastne podmienka riadiaca sa premennou $TERM. V tejto premennej je ulozeny nazov terminalu. Po podmienkach sa skace smerom z vrchu dole, cize najprv sa porovnava ci premenna neobsahuje retazce xterm*, aterm*, atd... Pokial ano, vykona sa cast kodu ulozena v ~/.prompt_xterm. Hviezdicka v nazve xterm* je wildcard, co znamena ze nahradza neurcitu cast retazca. Znak | je logicke OR (alebo). V druhej podmienke sa nastavi este aj premenna $PROMPT_COMMAND kvoli programu screen, v druhej obsahovej casti budeme vidiet ako to vyuzijeme pre hardstatus.

    Poznamka: pokial nebude sediet ziadne z uvedenych, uplatni sa posledna podmienka ktora definuje retazec ako 'cokolvek' a vysledkom bude ze sa nevykona nic. To znamena ze v $PS1 ostane bezfarebna definicia ktoru sme si zadefinovali na zaciatku (resp. ktora bola prednastavena).


    Obsah suboru .prompt_xterm:
    TITLEBAR="\[\033]0;$TERM - \u@\h:\w\007\]"
    
    PS1="$TITLEBAR\[\033[01;30m\][\[\033[00m\] \[\033[01;37m\]\h\[\033[00m\] \[\033[01;30m\]\w\[\033[00m\] \[\033[01;30m\]]\[\033[00m\]\n  \[\033[00;37m\]($TERM)\[\033[00m\] \[\033[01;36m\]\u\[\033[00m\] \\$ "
    

    Premennu $TITLEBAR tvori escape sekvencia pre graficke emulatory terminalu vdaka ktorej sa zobrazuje v ramiku okna, alebo na liste nazov programu ktory je vykonavany. Do premennej $PS1 je dosadena premenna $TITLEBAR a za nu retazec tvoreny specialnymi escape sekvenciami ktore popisuju farby a premenne ktorymi su nahradene (ako napr. nazov hostitela, uzivatel, cesta, atd..).

    Priklad: \[\033[01;36m\]\u - zobrazi meno uzivatela farbou CYAN (tyrkisova), nejake tie farebne kombinacie ste si mohli osvojit aj z predch. zapisku ls a dircolors.
    Zoznam escape sequences.

    Subor .prompt_xterm od vas "ocakava" ze si ho prisposobite. Obsah ktory ste mohli zhliadnut patri mojmu .prompt_xterm a to ze bol uvedeny ako priklad neznamena ze je to finalna podoba :)

    Poznamka: dalej v subore .bashrc by uz nemala nasledovat ziadna dalsia definicia $PS1 aby ste si jej obsah neprepisali, samozrejme tato poznamka pre pokrocilych uzivatelov nema zmysel.
    Poznamka: ja osobne nevkladam a nepouzivam premennu $debian_chroot, pokial mate ine potreby, je nutne si uvedene priklady upravit pre svoju potrebu. Taktiez pokial uvidite vo svojom .bashrc kadejake ine nespomenute vychytavky (napr. aj distribucne), zakomponujte si ich podla svojich potrieb.

    Obsah mojho .bashrc (ako priklad)
    # ~/.bashrc: executed by bash(1) for non-login shells.
    # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
    # for examples
    
    # If not running interactively, don't do anything
    [ -z "$PS1" ] && return
    
    # don't put duplicate lines in the history. See bash(1) for more options
    export HISTCONTROL=ignoredups
    export HISTCONTROL=ignoreboth
    
    # check the window size after each command and, if necessary,
    # update the values of LINES and COLUMNS.
    shopt -s checkwinsize
    
    # make less more friendly for non-text input files, see lesspipe(1)
    [ -x /usr/bin/lesspipe ] && eval "$(lesspipe)"
    
    # set variable identifying the chroot you work in (used in the prompt below)
    #if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    #    debian_chroot=$(cat /etc/debian_chroot)
    #fi
    
    # set a fancy prompt (non-color, unless we know we "want" color)
    #PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    PS1='[ \h \w ]\n  ($TERM) \u \$ '
    
    
    # If this is an xterm set the title to user@host:dir
    case "$TERM" in
    xterm*|aterm*|rxvt*|urxvt*)
    #    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}"'
            . ~/.prompt_xterm
        ;;
    screen*)
            . ~/.prompt_xterm
            PROMPT_COMMAND='echo -ne "\033k\033\\"'
        ;;
            *)
            ;;
    esac
    
    # Alias definitions.
    # You may want to put all your additions into a separate file like
    # ~/.bash_aliases, instead of adding them here directly.
    # See /usr/share/doc/bash-doc/examples in the bash-doc package.
    
    if [ -f ~/.bash_aliases ]; then
        . ~/.bash_aliases
    fi
    
    # enable color support of ls and also add handy aliases
    if [ "$TERM" != "dumb" ]; then
        eval "`dircolors -b`"
        alias ls='ls --color=auto'
        #alias dir='ls --color=auto --format=vertical'
        #alias vdir='ls --color=auto --format=long'
    fi
    

    Vysledok - Na lavej strane xterm a farebne upraveny prompt, na pravej strane hore v xterm bezi screen, na pravej strane dole xterm s parametrom -tn "vt100", farebne zvyraznenie sa neaplikuje (kvoli podmienke).


    screen a hardstatus

    Urcite ste si uz vsimli na mojich screenshotoch spodny riadok v spustenom programe screen. Je tam nazov hostitela, load, datum, cas a vypis spustenych okien. Narozdiel od promptu, v screene sa aj oplati mat cas a datum, kedze tieto informacie su prekreslovane vzdy pri nejakej udalosti (zmena casu, atd).

    Uvediem hned na zaciatok obsah mojho .screenrc:
    hardstatus alwayslastline
    hardstatus string '%{=b .W}%H (%{-b .B}%l%{=b .W}) %{= .K}| %{=b .R}%Y-%m-%d %{=b .Y}%c %{= .K}| %{=b .G}*%n%f %t %{= .K}| %{=b .k}%W'
    shelltitle "$ |bash"
    startup_message off
    nethack on
    vbell off
    

    Prvy riadok znaci ze hardstatus bude vzdy ako posledny zobrazovany riadok v okne, nasledujuci riadok konfiguruje zobrazovane informacie. Cely retazec je zmes textovych premennych ktore znacia farbu, umiestnenie, a informacnu hodnotu. Nebudem popisovat kazdu jednu, na to najlepsie posluzi manual, konkretne sekcia STRING ESCAPES.
    Uryvok:
    STRING ESCAPES
    
           Screen provides an escape mechanism to insert information like the cur-
           rent time into messages or file names. The escape character is '%' with
           one  exception:  inside  of  a  window's hardstatus '^%' ('^E') is used
           instead.
    
           Here is the full list of supported escapes:
    
           %      the escape character itself
    
           a      either 'am' or 'pm'
    
           A      either 'AM' or 'PM'
    
           c      current time HH:MM in 24h format
    
           C      current time HH:MM in 12h format
    
           d      day number
    
           D      weekday name
    
           f      flags of the window
    
           F      sets %? to true if the window has the focus
    
           h      hardstatus of the window
    
           H      hostname of the system
    
           l      current load of the system
    
           m      month number
    
           M      month name
    
           n      window number
    
           s      seconds
    
           t      window title
    
           u      all other users on this window
    
           w      all window numbers and names. With '-'  quailifier:  up  to  the
                  current  window;  with  '+'  qualifier: starting with the window
                  after the current one.
    
           W      all window numbers and names except the current one
    
           y      last two digits of the year number
    
           Y      full year number
    
           ?      the part to the next '%?' is displayed  only  if  a  '%'  escape
                  inside the part expands to a non-empty string
    
           :      else part of '%?'
    
           =      pad  the  string to the display's width (like TeX's hfill). If a
                  number is specified, pad  to  the  percentage  of  the  window's
                  width.   A  '0'  qualifier  tells  screen to treat the number as
                  absolute position.  You can specify to pad relative to the  last
                  absolute  pad position by adding a '+' qualifier or to pad rela-
                  tive to the right margin by using '-'. The padding truncates the
                  string  if  the specified position lies before the current posi-
                  tion. Add the 'L' qualifier to change this.
    
           <      same as '%=' but just do truncation, do not fill with spaces
    
           >      mark the current text position for  the  next  truncation.  When
                  screen  needs  to do truncation, it tries to do it in a way that
                  the marked position gets moved to the  specified  percentage  of
                  the  output  area.  (The  area starts from the last absolute pad
                  position and ends with the position specified by the  truncation
                  operator.)  The 'L' qualifier tells screen to mark the truncated
                  parts with '...'.
    
           {      attribute/color modifier string terminated by the next "}"
    
           `      Substitute with the output of a 'backtick' command.  The  length
                  qualifier is misused to identify one of the commands.
    
           The  'c'  and 'C' escape may be qualified with a '0' to make screen use
           zero instead of space as fill character. The '0' qualifier  also  makes
           the  '='  escape use absolute positions. The 'n' and '=' escapes under-
           stand a length qualifier (e.g. '%3n'), 'D' and 'M' can be prefixed with
           'L'  to  generate long names, 'w' and 'W' also show the window flags if
           'L' is given.
    
           An attribute/color modifier is is used to change the attributes or  the
           color  settings.  Its  format  is "[attribute modifier] [color descrip-
           tion]". The attribute modifier must be prefixed by a change type  indi-
           cator  if  it  can  be  confused with a color desciption. The following
           change types are known:
    
           +      add the specified set to the current attributes
    
           -      remove the set from the current attributes
    
           !      invert the set in the current attributes
    
           =      change the current attributes to the specified set
    
           The attribute set can either be specified as a hexadecimal number or  a
           combination of the following letters:
    
           d      dim
           u      underline
           b      bold
           r      reverse
           s      standout
           B      blinking
    
           Colors are coded either as a hexadecimal number or two letters specify-
           ing the desired background and foreground color (in  that  order).  The
           following colors are known:
    
           k      black
           r      red
           g      green
           y      yellow
           b      blue
           m      magenta
           c      cyan
           w      white
           d      default color
           .      leave color unchanged
    
           The  capitalized  versions of the letter specify bright colors. You can
           also use the pseudo-color 'i' to set just the brightness and leave  the
           color unchanged.
           A  one digit/letter color description is treated as foreground or back-
           ground color dependant on the current attributes: if  reverse  mode  is
           set,  the  background color is changed instead of the foreground color.
           If you don't like this, prefix the color with a ".". If  you  want  the
           same behaviour for two-letter color descriptions, also prefix them with
           a ".".
           As a special case, "%{-}" restores the attributes and colors that  were
           set  before the last change was made (i.e. pops one level of the color-
           change stack).
    
           Examples:
    
           "G"    set color to bright green
    
           "+b r" use bold red
    
           "= yd" clear all attributes, write in default  color  on  yellow  back-
                  ground.
    
           %-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<
                  The  available  windows centered at the current window and trun-
                  cated to the available width. The current  window  is  displayed
                  white  on  blue.   This can be used with "hardstatus alwayslast-
                  line".
    
           %?%F%{.R.}%?%3n %t%? [%h]%?
                  The window number and title and the window's hardstatus, if  one
                  is  set.  Also use a red background if this is the active focus.
                  Useful for "caption string".
    


    Riadok shelltitle "$ |bash" zabezpecuje ze pokial nebol dodany retazec pre pomenovanie okna tak nazov okna bude explicitne bash. Spominany retazec nie je nic ine ako escape sekvencia PROMPT_COMMAND='echo -ne "\033k\033\\"' (ktoru sme si uz spominali) a nazov vykonavaneho programu.

    Dalsie riadky konfiguracie uz nie su podstatne pre naplnenie temy.

    Vysledok.

    Pripomienky, navrhy a komentare poprosim do diskusie a pokial niekto docital az sem tak dakujem za vasu pozornost.        

    Hodnocení: 100 %

            špatnédobré        

    Tiskni Sdílej: Linkuj Jaggni to Vybrali.sme.sk Google Del.icio.us Facebook

    Komentáře

    Vložit další komentář

    10.1.2010 22:22 filbar | skóre: 36 | blog: Denicek_programatora | Ostrava
    Rozbalit Rozbalit vše Re: vylepsenie prompt-u a screen hardstatus
    Sice to s tím úplně nesouvisí, ale nevíte jak zruším poblikávání v screenu při tab completion?
    10.1.2010 23:50 Zdeněk Burda | skóre: 61 | blog: Zdendův blog | Praha
    Rozbalit Rozbalit vše Re: vylepsenie prompt-u a screen hardstatus
    man screen:

    C-a C-g (vbell) Toggles screen’s visual bell mode.
    -- Nezdar není hanbou, hanbou je strach z pokusu.
    asfethan avatar 11.1.2010 01:53 asfethan | skóre: 10 | blog: asfalatum | Bratislava
    Rozbalit Rozbalit vše Re: vylepsenie prompt-u a screen hardstatus
    Bud ako odpovedal komentujuci 'kolega' predomnou, alebo je to presne ta volba ktoru som dalej nekomentoval a sice vbell off v .screenrc
    11.1.2010 08:36 the human Yeoman
    Rozbalit Rozbalit vše Re: vylepsenie prompt-u a screen hardstatus
    Díky, ten status ve screenu je dobry napad ;-)

    Založit nové vláknoNahoru

    ISSN 1214-1267   www.czech-server.cz
    © 1999-2015 Nitemedia s. r. o. Všechna práva vyhrazena.