[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Pimp your shell - Debian developer tips?



Hi Otto,

On 5/27/20 9:06 PM, Otto Kekäläinen wrote:
> Do we have Debian devs here who have pimped their shell heavily with custom
> prompts, colors, command line fonts, shell window title hacks, perhaps
> using zsh etc? Have you written blogs about you experiences, can you share
> some good reads (with screenshots) of what you have done?

I'd like to share my solution to using my zsh environment/customization
while switching to root but without polluting root's configuration (or
any other user for that matter).

I have a function to call a sudo that runs a zsh shell (ignoring root
login shell) configured to use my config files instead of root:

s () {
        sudo -u "${1:-root}" -H "ZDOTDIR=${HOME}" -s /bin/zsh
}

Additionally to that, I have a section in my .zshrc that detect being
called as another user and setup aliases for my most used commands to be
called with rc files from my user:

# We got call as another user, let's setup our env
if [ -n "${ZDOTDIR}" ]; then
    alias vim="vim -u ${ZDOTDIR}/.vimrc"
    alias vimdiff="vimdiff -u ${ZDOTDIR}/.vimrc"
    alias git="HOME=${ZDOTDIR} git"
    alias htop="HTOPRC=${ZDOTDIR}/.config/htop/htoprc htop"
    alias t="tmux a || tmux -f <(cat ${ZDOTDIR}/.tmux.conf; echo set -g
default-shell /bin/zsh)"
    if [ -f "${ZDOTDIR}/.ssh/config" ]; then
        alias ssh="ssh -F ${ZDOTDIR}/.ssh/config"
        alias rsync="rsync -e \"ssh -F ${ZDOTDIR}/.ssh/config\""
    fi
    export SSH_AUTH_SOCK="$(grep -z SSH_AUTH_SOCK /proc/$(ps -p ${PPID}
--format=ppid --no-headers)/environ -a 2> /dev/null| cut -d = -f 2)"
    export EDITOR="vim -u ${ZDOTDIR}/.vimrc"
    [ -f "${ZDOTDIR}/.identity" ] && source "${ZDOTDIR}/.identity"
    export GNUPGHOME="${ZDOTDIR}/.gnupg"
fi

In practice, I can `s` or `s postgres` to switch to root or postgres
user continuing to use my config, without polluting user's config.

Obviously, unix permisson apply and restrict what you can read/do when
switching to another user beside root.

-- 
Baptiste BEAUPLAT - lyknode

Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: