From c9a9e9780a3ba43f99adc1bb3ddbeb19498f05af Mon Sep 17 00:00:00 2001 From: Maxim Likhachev Date: Thu, 30 Jul 2020 21:22:10 +0300 Subject: [PATCH] bash, vifm: refactoring --- etc/shell/bash/aliases | 68 +++++++++++++++++------------------ etc/shell/bash/bash_completion_custom | 6 ++-- etc/shell/bash/bashrc | 37 ++++++++----------- etc/shell/bash/inputrc.root | 2 ++ etc/soft/vifm/colors/custom.vifm | 11 ++++-- etc/soft/vifm/commands | 3 +- 6 files changed, 64 insertions(+), 63 deletions(-) create mode 100644 etc/shell/bash/inputrc.root diff --git a/etc/shell/bash/aliases b/etc/shell/bash/aliases index ff11ef3..2070262 100755 --- a/etc/shell/bash/aliases +++ b/etc/shell/bash/aliases @@ -4,6 +4,8 @@ #{{{ Псевдонимы ################################################################################ +alias aliases="alias | vcat -l sh" + alias ~='cd ~' #noindex alias ..='cd ..' #noindex alias .-='cd -' #noindex @@ -43,11 +45,12 @@ alias pstree="pstree -U -h" #noindex alias mkdir="mkdir -p -v" #noindex alias j="jobs -l" #noindex alias dirs="dirs -v" #noindex -alias emerge="emerge --ask" #noindex alias rg='rg --no-heading --smart-case --color=auto --colors "match:bg:yellow" --colors "match:fg:blue"' #noindex -alias eww='emerge --update --newuse --deep --with-bdeps=y --complete-graph=y --keep-going=y -av --verbose-conflicts -t @world' #noindex alias xlock="i3lock -i $SHELLRC/etc/wm/img/locker.png" #noindex +alias emerge="emerge --ask" #noindex +alias eww='emerge --update --newuse --deep --with-bdeps=y --complete-graph=y --keep-going=y -av --verbose-conflicts -t @world' #noindex + #- Замена стандартных путей для конфигурационных файлов alias newsboat="newsboat -r" #noindex alias mpd="mpd $SHELLRC/etc/media/mpd/mpd.conf" #noindex @@ -69,9 +72,8 @@ alias fm="nnn" #noindex alias glow="glow --style light" #noindex if [ $UID -eq 0 ]; then - alias mc="TERM=xterm-256color mc -S modarin256root" + alias htop="htop" else - alias mc="TERM=xterm-256color mc -S modarin256" alias htop="htop -u $(whoami)" fi @@ -90,8 +92,8 @@ nh() { } #- Правка псевдонимов в Vim -function ealias() { #noindex - $EDITOR ${HELPSRC[*]} +ealias() { #noindex + $EDITOR "${HELPSRC[@]}" } #- Перезагрузка конфигов баша @@ -111,16 +113,14 @@ h() { #noindex } #Переназначение функции, вызываемой неизвестной командой -command_not_found_handle() { #noindex +command_not_found_handle() { #noindex if [ -d "$1" ]; then cd "$1" else - echo $1 | grep '[фывапролджэйцукенгшщзхъячсмитьбю]' 2>&1 > /dev/null - - if [ $? == 0 ]; then - ex="$(echo -n $@ | \ + if grep -q '[фывапролджэйцукенгшщзхъячсмитьбю]' 2>&1 > /dev/null <<<"$1"; then + ex="$(echo -n "$@" | \ sed "y/йцукенгшщзхъфывапролджэячсмитьбю\.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,/qwertyuiop\[\]asdfghjkl;\'zxcvbnm,\.\/QWERTYUIOP\{\}ASDFGHJKL:\"ZXCVBNM<>\?/")" - echo "$red[$@] -> $green[$ex]$rstc" + echo "${red}[$@] -> ${green}[${ex}]${rstc}" bash --rcfile ~/.bashrc -c "$ex" else echo >&2 "${red}Команда ${green}${1}${red} не найдена.$rstc" @@ -174,9 +174,7 @@ toph() { alias path='echo -e ${PATH//:/\\n} | nl' #- Взятие строк в кавычки -quote() { - sed 's/^\|$/"/g' -} +alias quote="sed 's/^\|$/\"/g'" #}}} ########################################################################### #{{{ \033[00m\n\b------<Работа_с_файлами>\n @@ -187,7 +185,7 @@ alias z="nh zathura" #noindex #- tabbed zathura; noindex zt() { - tabbed -c zathura "$@" -e + nh tabbed -c zathura "$@" -e } #- Написание текстов в Vim @@ -233,9 +231,11 @@ xc() { #- Переход с поиском выше по дереву директорий up() { - [[ "$1" == "" ]] && cd .. \ - || cd $(echo $PWD | \grep -o "^.*$1\/" \ - || (echo "${red}Путь $1 не найден${rstc}" >&2 && echo ".") ) + if [[ -z "$1" ]]; then + cd .. + else + cd "$(echo "$PWD" | \grep -o "^.*$1\/" || (echo "${red}Путь $1 не найден${rstc}" >&2 && echo ".") )" + fi } #- koi8r -> utf8 @@ -290,9 +290,9 @@ ttr() { toread() { BASEDIR="$HOME/FILES/_Книги/Прочесть" - [ ! -z "$2" ] && mkdir -p "$BASEDIR/$2" + [ -n "$2" ] && mkdir -p "$BASEDIR/$2" - ln -s "`realpath "$1"`" "$BASEDIR/${2:-.}/$1" + ln -s "$(realpath "$1")" "$BASEDIR/${2:-.}/$1" } #- Просмотр файла с подсветкой синтаксиса @@ -303,26 +303,26 @@ src() { vcat "$1" | less -R; } #- Поиск пути к исполняемому файлу, просмотр кода функций и псевдонимов which() { #noindex - RESULT=$((alias; declare -f) \ + RESULT=$({ alias; declare -f; } \ | /usr/bin/which \ --tty-only \ --read-alias \ --read-functions \ --show-tilde \ - --show-dot $@) + --show-dot "$@") - ([ -n "$RESULT" ] && echo "$RESULT" || type $@) | vcat -l bash + ([ -n "$RESULT" ] && echo "$RESULT" || type "$@") | vcat -l bash } 2>/dev/null #- Переход в директорию файла cdwhich() { - cd $(dirname $(/usr/bin/which $1)) + cd "$(dirname "$(/usr/bin/which "$1")")" } #- Редактирование скриптов dowhich() { #noindex - eval $1 $(/usr/bin/which $2) + eval "$1" "$(/usr/bin/which "$2")" } #- Редактирование скриптов @@ -333,14 +333,14 @@ alias vcatwhich="dowhich vcat" #noindex #- Список уникальных слов с количеством вхождений wcu() { - cat "$1" | tr -cs A-Za-z\' '\n' | tr A-Z a-z | sort | uniq -c | sort -nr | nl + grep -o -E '\w+' "$1" | tr "[:upper:]" "[:lower:]" | sort | uniq -c | sort -nr | nl } #- Выполнение команды для всех файлов: apply cmd -1 -2 @ *.file apply() { CMD="" - for argument in $@; { + for argument in "$@"; { if [ "$argument" != "@" ]; then CMD+=" $argument"; shift else @@ -363,17 +363,17 @@ function mount() { #noindex #- Копирование файла $1 в $SHELLRC/bin/$2 cpbin() { - cp -i $1 $SHELLRC/bin/$2/ + cp -i "$1" "$SHELLRC/bin/$2/" } #- Перемещение файла $1 в $SHELLRC/bin/$2 mvbin() { - mv -i $1 $SHELLRC/bin/$2/ + mv -i "$1" "$SHELLRC/bin/$2/" } #- Создание символической ссылки на файл $1 в $SHELLRC/bin/$2 lnbin() { - ln -i -s $(realpath $1) "$SHELLRC/bin/$2/$1" + ln -i -s "$(realpath "$1")" "$SHELLRC/bin/$2/$1" } #}}} ########################################################################### @@ -395,12 +395,12 @@ restart() { su -c "/etc/init.d/$1 restart"; } #- Прогноз погоды weather() { - curl -H "Accept-Language: ${LANG%_*}" wttr.in/${@} + curl -H "Accept-Language: ${LANG%_*}" "wttr.in/$*" } #- Фаза Луны moon() { - weather "moon?${@}" + weather "moon?$*" } #- Карта мира @@ -410,7 +410,7 @@ map() { #- Отображение настоящего URL ссылки realurl() { - curl -ILs "$1" | grep '^Location:' + curl -ILs "$1" | grep '^Location:' } #- Консольный калькулятор diff --git a/etc/shell/bash/bash_completion_custom b/etc/shell/bash/bash_completion_custom index 9445a57..9554e3b 100755 --- a/etc/shell/bash/bash_completion_custom +++ b/etc/shell/bash/bash_completion_custom @@ -1,6 +1,6 @@ #!/bin/bash ######################### # -# Изменён: Чт 27 фев 2020 00:31:10 +# Изменён: Чт 30 июл 2020 21:09:02 # #complete <что дополнять> <программа> @@ -79,9 +79,9 @@ _local-bins () { fi } -complete -F _local-bins vimwhich catwhich nlwhich +complete -F _local-bins vimwhich catwhich nlwhich cdwhich -complete -c command cdwhich +complete -c command cdwhich vimwhich catwhich nlwhich # Функция, т.к. grep позволяет дополнять подстроку в любом регистре _updirs() { diff --git a/etc/shell/bash/bashrc b/etc/shell/bash/bashrc index 5ddc6b0..f28fc65 100755 --- a/etc/shell/bash/bashrc +++ b/etc/shell/bash/bashrc @@ -1,6 +1,6 @@ #!/bin/bash #################################################################### # -# Изменён: Чт 30 июл 2020 18:23:04 +# Изменён: Чт 30 июл 2020 20:38:07 # ################################################################################ @@ -47,20 +47,18 @@ export LESSOPEN="|/usr/bin/lesspipe.sh %s" export LESSHISTFILE=/dev/null export LESSCOLOR=yes -export LC_ALL=ru_RU.UTF-8 #Системная локаль -export PRINTER=HP_LaserJet_P1005 #Принтер по умолчанию +#Системная локаль +export LC_ALL=ru_RU.UTF-8 +export LC_CTYPE=ru_RU.UTF-8 export IGNOREEOF=3 #Закрывать оболочку по 3м C-d export LOGDIR=$SHELLRC/var/log #Директория журналов скриптов -export TODO=$SHELLRC/etc/soft/calcurse/todo #Список дел export MD=$SHELLRC/var/mail/ #Директория почты export MAILCAPS=$SHELLRC/etc/mail/mailcap/mailcap #~/.mailcap export CRON=$SHELLRC/etc/cron/crontab #Задания cron export TMP="/tmp" #Директория временных файлов -export JAVA_HOME="/usr/lib/jvm/oracle-jdk-bin-1.8/" - #Настройки nnn export NN_USE_EDITOR=1 @@ -70,7 +68,7 @@ export NOCOLOR_PIPE=1 #Настройки компилятора export CFLAGS="-O2 -pipe" -export MAKEOPTS="-j `getconf _NPROCESSORS_ONLN`" +export MAKEOPTS="-j $(getconf _NPROCESSORS_ONLN)" #Формат времени, выводимый командой time # real 0m32.155s @@ -80,7 +78,7 @@ export MAKEOPTS="-j `getconf _NPROCESSORS_ONLN`" # export TIMEFORMAT=$'real\t%3lR\nuser\t%3lU\nsys\t%3lS\nCPU\t%P%' -#Настройка TOR + Privoxy +#Настройка прокси export http_proxy= export HTTP_PROXY= # http_proxy=http://127.0.0.1:8118/ @@ -88,12 +86,6 @@ export HTTP_PROXY= # HTTP_PROXY=$http_proxy # export http_proxy HTTP_PROXY proxy_address -export SBCL_HOME=/usr/lib/sbcl - -export MPLAYER_HOME=$HOME/.config/mplayer -export GIMP2_DIRECTORY=$HOME/.local/share/gimp-2.8 -export VIMDIR=$SHELLRC/etc/soft/vim/vim - # }}} ########################################################################## # {{{ Опции подсветки ################################################################################ @@ -172,6 +164,9 @@ if [ $UID -eq 0 ]; then PROMPT_COLOR='\033[1;31m' export HOME=/root + # root's inputrc + bind -f "$BASHRC/inputrc.root" 2>/dev/null + path++ $INIT_PATH PATH path++ /sbin PATH path++ /usr/sbin PATH @@ -187,7 +182,7 @@ fi # {{{ Подключение псевдонимов ################################################################################ -[ -f $BASHRC/aliases ] && ALIASES="$BASHRC/aliases" && . $ALIASES && HELPSRC+=("$ALIASES") +[ -f "$BASHRC/aliases" ] && ALIASES="$BASHRC/aliases" && . "$ALIASES" && HELPSRC+=("$ALIASES") #Раскрывать псевдонимы в скриптах # shopt -s expand_aliases @@ -237,9 +232,9 @@ __prompt_command() { PS1="${PS1_JOBS}${PS1_HOST}${PS1_PATH}\n${PROMPT_COLOR}─[${PROMPT_COLOR}\t]" if [ $EXIT != 0 ]; then - PS1+="${red}\$ ${rstc}" + PS1+="${red}\\$ ${rstc}" else - PS1+="${green}\$ ${rstc}" + PS1+="${green}\\$ ${rstc}" fi } @@ -258,8 +253,8 @@ export PROMPT_DIRTRIM=3 #В приглашении показывать 3 ди export BASH_COMPLETION="$BASHRC/bash_completion" -[ -f $BASHRC/bash_completion ] && . $BASHRC/bash_completion -[ -f $BASHRC/bash_completion_custom ] && . $BASHRC/bash_completion_custom +[ -f "$BASHRC/bash_completion" ] && . "$BASHRC/bash_completion" +[ -f "$BASHRC/bash_completion_custom" ] && . "$BASHRC/bash_completion_custom" # }}} ########################################################################## # {{{ Настройка истории команд @@ -324,13 +319,11 @@ bind '"\C-r": "\C-ahh \C-j"' # bind '"\C-r": "\C-aprintf \033c\e]20;;100x100+1000+1000\a \C-j"' #commacd -source $SHELLRC/etc/shell/bash/commacd +source "$SHELLRC/etc/shell/bash/commacd" # alias grep="/usr/bin/grep $GREP_OPTIONS" unset GREP_OPTIONS -export LC_CTYPE="ru_RU.UTF-8" - #Исправление ошибок с набором акцентов # if [ "$TERM" == "xterm" ]; then printf '\33]701;%s\007' "$LANG" diff --git a/etc/shell/bash/inputrc.root b/etc/shell/bash/inputrc.root new file mode 100644 index 0000000..ae0ce51 --- /dev/null +++ b/etc/shell/bash/inputrc.root @@ -0,0 +1,2 @@ +set vi-ins-mode-string "\1\e[31;1m\2└─\1\e[34;1m\2(I)\1\e[0m\2" +set vi-cmd-mode-string "\1\e[31;1m\2└─\1\e[31;1m\2[N]\1\e[0m\2" diff --git a/etc/soft/vifm/colors/custom.vifm b/etc/soft/vifm/colors/custom.vifm index 663df4e..3473788 100644 --- a/etc/soft/vifm/colors/custom.vifm +++ b/etc/soft/vifm/colors/custom.vifm @@ -33,9 +33,6 @@ highlight Selected cterm=bold ctermfg=22 ctermbg=230 highlight CurrLine cterm=bold ctermfg=255 ctermbg=103 -" ROOT -" highlight CurrLine cterm=bold ctermfg=255 ctermbg=160 - highlight TabLine cterm=none ctermfg=236 ctermbg=250 highlight TabLineSel cterm=bold ctermfg=236 ctermbg=152 @@ -63,3 +60,11 @@ highlight CmdLine cterm=bold ctermfg=255 ctermbg=24 highlight ErrorMsg cterm=bold ctermfg=255 ctermbg=160 +" overwrite some colors for root user +if $USER == 'root' + highlight TopLine cterm=bold ctermfg=255 ctermbg=160 + highlight TopLineSel cterm=bold ctermfg=255 ctermbg=160 + highlight CurrLine cterm=bold ctermfg=255 ctermbg=130 + highlight CmdLine cterm=bold ctermfg=255 ctermbg=160 +endif + diff --git a/etc/soft/vifm/commands b/etc/soft/vifm/commands index 1d07c1f..f2917b5 100644 --- a/etc/soft/vifm/commands +++ b/etc/soft/vifm/commands @@ -45,7 +45,8 @@ command xc xc %c command config :nvim $MYVIFMRC -command z !!zathura %c:p +command z !!zathura %c:p +command zt !!zt %f command renamepdfs !renamepdfs --directory %d %f