:: Re: [DNG] New behaviour under Devua…
Page principale
Supprimer ce message
Répondre à ce message
Auteur: Adam Borowski
Date:  
À: dng
Sujet: Re: [DNG] New behaviour under Devuan.
On Sat, Sep 23, 2017 at 09:45:04PM +0200, Didier Kryn wrote:
>     Means you must have one terminal profile for every location you ssh to.
> And you forbid yourself to use su or ssh from the command line, because this
> doesn't change the color scheme of the terminal.


~/.bashrc gets re-run on su, and of course on all regular logins (local or
ssh).

>     It's pretty heavy to manage all the necessary terminal profiles - I used
> gnome-terminal when I experimented with this method, a dozen years ago. I
> eventually found it complicated my life a lot.


I distribute my bashrc to all hosts (preferably as a package, although this
works only for hosts under my direct control). It then runs ~/.bashrc_local
if it exists, allowing for ad-hoc customization.

The part that deals with prompts is:
==============================================================================
# show git branch in git repos if git is installed
if [ -x /usr/bin/git ]
  then
    git_branch='$(parse_git_branch)'
    function parse_git_branch
    {
        git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
    }
fi


case "$HOSTNAME" in
  umbar)        PSC1='\e[0;36m';;
  moria)        PSC1='\e[0;32m';;
  andunie)      PSC1='\e[0;38;5;107m' PSC2='\e[0;1;38;5;193m';;
  harlond)      PSC1='\e[0;1;32m' PSC2='\e[0;32m';;
  sirius)       PSC1='\e[0;38;5;137m' PSC2='\e[0;38;5;223m';;
  canopus)      PSC1='\e[0;38;5;214m' PSC2='\e[0;38;5;130m';;
  rigel)        PSC1='\e[0;38;5;204m' PSC2='\e[0;38;5;125m';;
  utumno)       PSC1='\e[0m' PSC2='\e[0;33m';;
  isengard)     PSC1='\e[0;30;1m' PSC2='\e[0;37m';;
  deneb|denebola)
                PSC1='\e[0;33m';;
  barad-dur|mordor|morannon|carchost|narchost|orodruin|durthang|isenmouthe|\
  minas-morgul|cirith-ungol|ephel-duath|torech-ungol|gorgoroth|lithlad|\
  nurn|nurnen|ered-lithui|minas-ithil|lair|dol-guldur|angband|eye|morgai|\
  cirith-gorgor)
                PSC1='\e[0;1;35m' PSC2='\e[0;35m' PSH=1;;
  abyss|styx|cocytus|dis|malebolge|phlegeston|avernus|acheron|erebus|tartarus|lethe)
                PSC1='\e[0;31m' PSH=1;;
  numenor)      PSC1='\e[0;1;36;44m' PSC2='\e[0;37;44m';;
  lorien)       PSC1='\e[0;1;30m' PSC2='\e[0;1m';;
  kholdan)      PSC1='\e[0;38;5;25m' PSC2='\e[0;1;38;5;69m';;
  altair|ursa|nazin|draconis|gnol|sol|meklon|fieras|mentar|sssla|cryslon|trilar|\
  antares|orion)
                PSC1='\e[0;35m' PSH=1;;
  *)            PSC1='\e[0;1;31m' PSC2='\e[0;31m' PSH=1;;
esac
# If PSH is set, prompt will be prefixed by the hostname.


export PS1="${PSH:+\\[$PSC1\\]\\h}\\[${PSC2:-$PSC1\\e[1m}\\]${PSH:+:}[\\[$PSC1\\]\\w\\[${PSC2:-\\e[1m}\\]]\\[\\e[0;1;33m\\]$git_branch\\[\e[\${PROMPT_ERRORC}m\\]\$PROMPT_ERROR\\[\\e[0;1;33m\\]\\$\\[\e[?2004l\\e[0m\\] "
export PS2='\[\e[1;33m\]>\[\e[0m\] '
unset git_branch

case "$TERM" in
xterm*|rxvt*|linux*)
    PROMPT_COMMAND='if ((ERROR=$?))
      then
        if [ "$ERROR" -gt 128 ]
          then
            ERRORSIG="$(kill -l $(($ERROR-128)) 2>/dev/null)"
            [ -n "$ERRORSIG" ] && ERROR="$ERRORSIG"
        fi
        PROMPT_ERRORC="0;33;1;41"
        PROMPT_ERROR="$ERROR"
      else PROMPT_ERROR=""
    fi'
    ;;
*)
    ;;
esac


[ -n "$SCHROOT_CHROOT_NAME" ] && export PS1="\[\e[0;1m\]{$SCHROOT_CHROOT_NAME}\[\e[0m\]@$PS1"

case "$TERM" in
xterm*|rxvt*)
    if [ "$UID" == "0" ]
      then
          RH=`echo "$HOSTNAME"|tr a-z A-Z`
    fi
    if [ -z "${BASH_VERSION/#4.3.*/}" -o -z "${BASH_VERSION/#4.4.*/}" ]
      then
        PROMPT_COMMAND+=';echo -ne "\033]0;${SCHROOT_CHROOT_NAME:+{$SCHROOT_CHROOT_NAME\} }${RH:-$HOSTNAME}: ${PWD/#$HOME/\~}\033\\"'
      else
        PROMPT_COMMAND+=';echo -ne "\033]0;${SCHROOT_CHROOT_NAME:+{$SCHROOT_CHROOT_NAME\} }${RH:-$HOSTNAME}: ${PWD/#$HOME/~}\033\\"'
    fi
    ;;
*)
    ;;
esac
==============================================================================


$TERM handling can be dropped if you don't ever use Hurd/*BSD nor Linux
console earlier than 3.14.

Goodies in the above:
* git branches
* color-coded hosts; stand-alones have just a color, contained/clustered
ones also their hostnames
* errors from previous commands (I used to have fancy-schmancy powerline on
the right side but this was tedious when pasting)
* schroot names
* hostname in window title

I mark root prompt only by \$ (ie, $ vs #) and by hostname turning to
all-caps, but you can do whatever you want. If you want to alter color
scheme of the terminal, you can RTFS vtgamma to see how.


Meow!
--
⢀⣴⠾⠻⢶⣦⠀ I've read an article about how lively happy music boosts
⣾⠁⢰⠒⠀⣿⡁ productivity. You can read it, too, you just need the
⢿⡄⠘⠷⠚⠋⠀ right music while doing so. I recommend Skepticism
⠈⠳⣄⠀⠀⠀⠀ (funeral doom metal).