Bash

De WikiMar
Dreceres ràpides: navegació, cerca

Personalitzacions bashrc

Cal mirar el fitxer comu /etc/bash/bashrc (Gentoo) o bé /etc/bash.bashrc (Suse) contingui:

Per personalitzar un usuari en concret, editar ~/.bashrc

Prompt amb color

if [[ ${EUID} == 0 ]] ; then
  PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
else
  PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
fi


Si és \w es tot el cami si és \W només directori actual:

\! History number of current command
\# Command number of current command
\d Current date
\h Host name
\n Newline
\s Shell name
\t Current time
\u User name
\W Current working directory
\w Current working directory (full path)

Prompt color Original de Ubuntu

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
    else
        color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

Posar titol a les finestres

Apareix al connectar amb SSH, o obrir xterm.

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
   PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
   ;;
*)
   ;;
esac


Fer que tinguin color les comandes

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
   test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
   alias ls='ls --color=auto'
   alias dir='dir --color=auto'
   alias vdir='vdir --color=auto'
   alias grep='grep --color=auto'
   alias fgrep='fgrep --color=auto'
   alias egrep='egrep --color=auto'
fi

Alies útils

Per fer Alies de comandes afegir al final de ~/.bashrc:

alias l='ls -alF'
alias ..='cd ..'
alias ...='cd ../..'

Alies utils Originals Ubuntu

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# 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


Resum Tot usat per mi

A afegir al final de ~/.bashrc o millor al /etc/bashrc /etc/bash.bashrc per tal que sigui per tots els usuaris

(Veure també Screen_-_Finestra_de_commandes#Personalitzar_opcions_.screenrc)

(Veure també Vim)

(Veure també SSH#Configuracio_afegida_.2Fetc.2Fssh.2Fsshd_config)

# Afegit Marti:


if [[ ${EUID} == 0 ]] ; then
  # PS1='\[\033[01;31m\]\h \t \! $?\[\033[01;34m\] \w \$\[\033[00m\] '
  PS1='\[\033[01;31m\]\h \D{%Y%m%d_%H%M%S} \! $?\[\033[01;34m\] \w \$\[\033[00m\] '
else
  PS1='\[\033[01;32m\]\u@\h \D{%Y%m%d_%H%M%S} \! $?\[\033[01;34m\] \w \$\[\033[00m\] '
fi

# If this is an xterm set the title to user@host:dir  (also for the title of the cygwin windows)
case "$TERM" in
xterm*|rxvt*)
   PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
   ;;
*)
   ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    alias dir='dir --color=auto'
    alias vdir='vdir --color=auto'
    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

alias l='ls -alF'
alias ..='cd ..'
alias ...='cd ../..'

alias vi='vim'
alias sudo='sudo '
# http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo/22043#22043

alias sshignore='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
alias sshp='ssh -p 23'
alias moshp23='mosh --ssh "ssh -p23" '
# ps aux | awk '$8 ~ /D/ { print $0 }'
alias defunctps='ps aux | awk '"'"'$8 ~ /D/ { print $0 }'"'"
alias grec='grep -C999 --color=auto'
alias colt='column -t'
alias ip='ip -c'

# https://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTSIZE=1000000
export HISTFILESIZE=2000000
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"

# Use the arrow up and down to autocomplete using history and PGUP and PGDOWN to search like Ctrl-R
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
bind '"\e[5~": reverse-search-history'
bind '"\e[6~": forward-search-history'


També crear la configuracio .screenrc screen

En cas de usar /bin/ash

Editar /bin/profile

export PS1='\[\e]0;\u@\h: \w\a\033[01;32m\]\u@\h \t \! $?\[\033[01;34m\] \w \$\[\033[00m\] '


Shell amb colors

sudo apt install zsh
sudo apt install zsh-syntax-highlighting

https://www.kali.org/tools/zsh-syntax-highlighting/

exa = ls amb colors

apt install exa

https://the.exa.website