bashrc

   1 [[ $- != *i* ]] && return
   2 
   3 TERM=${OLDTERM:-$TERM}
   4 test -f ~/.theme/$VIM${TERM:0:5} && cat $_
   5 test -n "$SSH_TTY" && pfetch && colors -cc
   6 
   7 stty -ixon
   8 shopt -s autocd
   9 shopt -s globstar
  10 shopt -s lithist
  11 
  12 HISTFILESIZE= HISTSIZE=
  13 HISTTIMEFORMAT='[%F %T] '
  14 HISTCONTROL=ignorespace:ignoredups
  15 
  16 PROMPT_COMMAND=precmd
  17 function precmd(){ # {{{
  18     history -a
  19 
  20     test -f ~/.theme/$VIM${TERM:0:5} && cat $_
  21     ps1_col=$(( (${ps1_col:-$RANDOM} + 1) % 6 ))
  22 
  23     printf '\e]0;%s%s@%s:%s\a' "${SSH_TTY:+$(icon os) }" $USER $HOSTNAME "${PWD/~/\~}"
  24 } # }}}
  25 
  26 PS1='\n\[\e[1;3`ps1_col`m\] `ps1_ssh`\w`ps1_git` \$\[\e[0m\] '
  27 function ps1_col(){ # {{{
  28     [[ $SUDO_UID ]] && echo 1 || echo $(( ps1_col + 2 ))
  29 } # }}}
  30 function ps1_ssh(){ # {{{
  31     [[ $SSH_TTY ]] && echo $(icon os) $USER@$HOSTNAME:
  32 } # }}}
  33 function ps1_git(){ # {{{
  34     git rev-parse 2>&-|| return
  35 
  36     local st=$(git st  2>&- | wc -l)
  37     local up=$(git out 2>&- | wc -l)
  38     local br=$(git symbolic-ref --short HEAD)
  39 
  40     echo " [$br:*$up:+$st]" | sed 's/:[+*]0//g'
  41 } # }}}
  42 
  43 alias v='vi'
  44 alias vi='vim -p'
  45 
  46 alias gt='git'
  47 alias rg='ranger'
  48 alias tm='tmux a || tmux'
  49 
  50 alias l='cd ~/Lexa.by'
  51 alias d='cd ~/.dotfiles'
  52 
  53 alias ll='ls  -h  --color'
  54 alias lll='ll -al --time-style="+%F %T"'
  55 
  56 alias ip='ip -color=auto'
  57 alias grep='grep -i --color'
  58 alias dfc='dfc -wdq name -p /dev'
  59 
  60 alias rsync='rsync -ihv -rtl'
  61 alias backup='rsync -F /home/ /data/Бекапы/'
  62 alias backup-camera='rsync /run/**/DCIM/*/ ~/Камера/'
  63 
  64 alias mpv-audio='mpv --profile=audio'
  65 alias mpv-fan='(read u; mpv $(curl -s $u | grep -ao "https:.*\.mp4")) <<<'
  66 
  67 alias filvice='theme --filvice'
  68 alias lilvice='theme --lilvice'
  69 
  70 [[ $TERM == xterm ]] && printf '\e[0 q'
  71 [[ $TERM == linux || $TERM == xterm* ]] && OLDTERM=$TERM TERM=xterm
  72 
  73 test -f /usr/share/bash-completion/bash_completion && source $_
  74 command -v command_not_found_handle >&- || command_not_found_handle(){ # {{{
  75     local cmd pkg
  76 
  77     if command -v pkgfile >&-; then
  78         cmd='pacman -S'
  79         pkg=$(pkgfile -qb $1)
  80     elif command -v pacman >&-; then
  81         cmd='pacman -S'
  82         pkg=$(pacman  -Fq $1)
  83         pkg=${pkg[@]#*/}
  84     elif command -v apk >&-; then
  85         cmd='apk add'
  86         pkg=$(apk search -q cmd:$1)
  87     elif command -v pkglocate >&-; then
  88         cmd='pkg_add -vv'
  89         pkg=$(pkglocate bin/$1 | cut -d : -f 1 | sort -u)
  90     elif command -v xlocate >&-; then
  91         cmd='xbps-install -S'
  92         pkg=$(xlocate bin/$1 | sed 's/-[^-]*\t.*$//'| sort -u)
  93     fi
  94 
  95     [[ ! $pkg ]] && echo "$1: команда не найдена" && return 1
  96 
  97     echo
  98     echo "Команда «$1» не найдена, но может быть установлена с помощью:"
  99     echo
 100     printf "sudo $cmd %s\n" ${pkg[@]} | sort -u
 101     echo
 102 } # }}}
 103