Перейти к содержанию

▍Дотфайлы

Bash

nano ~/.bashrc
export LANG=ru_RU.utf8
export LANGUAGE=ru_RU.utf8
export LC_ALL=ru_RU.utf8

. $HOME/.alias #bash alias

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# variables for convenient PS1 construction 
txtblk='\[\e[0;30m\]' # Black - Regular
txtred='\[\e[0;31m\]' # Red
txtgrn='\[\e[0;32m\]' # Green
txtylw='\[\e[0;33m\]' # Yellow
txtblu='\[\e[0;34m\]' # Blue
txtpur='\[\e[0;35m\]' # Purple
txtcyn='\[\e[0;36m\]' # Cyan
txtwht='\[\e[0;37m\]' # White
bldblk='\[\e[1;30m\]' # Black - Bold
bldred='\[\e[1;31m\]' # Red
bldgrn='\[\e[1;32m\]' # Green
bldylw='\[\e[1;33m\]' # Yellow
bldblu='\[\e[1;34m\]' # Blue
bldpur='\[\e[1;35m\]' # Purple
bldcyn='\[\e[1;36m\]' # Cyan
bldwht='\[\e[1;37m\]' # White
unkblk='\[\e[4;30m\]' # Black - Underline
undred='\[\e[4;31m\]' # Red
undgrn='\[\e[4;32m\]' # Green
undylw='\[\e[4;33m\]' # Yellow
undblu='\[\e[4;34m\]' # Blue
undpur='\[\e[4;35m\]' # Purple
undcyn='\[\e[4;36m\]' # Cyan
undwht='\[\e[4;37m\]' # White
bakblk='\[\e[40m\]'   # Black - Background
bakred='\[\e[41m\]'   # Red
bakgrn='\[\e[42m\]'   # Green
bakylw='\[\e[43m\]'   # Yellow
bakblu='\[\e[44m\]'   # Blue
bakpur='\[\e[45m\]'   # Purple
bakcyn='\[\e[46m\]'   # Cyan
bakwht='\[\e[47m\]'   # White
txtrst='\[\e[0m\]'    # Text Reset

#Personal colors for root
case $(id -u) in
    0)
        STARTCOLOUR=$txtred;
        PROMPT="$bldred # $txtrst";
        ;;
    *)
        STARTCOLOUR=$txtylw;
        PROMPT="$bldgrn > $txtrst";
        ;;
esac

TXTGRN='\[\e[0;32m\]' # Green
TXTRST='\[\e[0m\]'    # Text Reset
TXTCYN='\[\e[0;36m\]' # Cyan
TXTPUR='\[\e[0;35m\]' # Purple
TXTYLW='\[\e[0;33m\]' # Yellow

# Prompt
IP=$(hostname -i | awk '{print $1}')
PS1="\n┌─( $TXTGRN\u@$txtylw$IP$TXTRST ) - ( $TXTPUR$(ls -1 | wc -l | sed 's: ::g') files, \$(ls -lah | grep -m 1 итого | sed 's/итого //')$TXTRST ) - ( $TXTCYN\w$TXTRST )\n└─> "

which dircolors &>/dev/null && eval $(dircolors ~/.dir_colors)

# don't put duplicate lines in the history. See bash(1) for more options
export HISTCONTROL=ignoredups
# ... and ignore same sucessive entries.
export HISTCONTROL=ignoreboth

#export PATH="$HOME/bin:$PATH"
#export PATH="/sbin:$PATH"
export PATH="$HOME/bin:/root/bin:/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin:$PATH"
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# 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

unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
    ;;
*)
    ;;
esac

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

# ALT

if [ -f $HOME/.alt ]; then
    . $HOME/.alt #bash alias alt
fi

if [ -f /etc/bashrc.d/bash_completion.sh ]; then
    . /etc/bashrc.d/bash_completion.sh
fi

#
HISTSIZE=10000
HISTFILESIZE=10000
nano ~/.alias
######################################################
# misc
alias df='df -h| grep -v snap| grep -v tmpfs'
alias ls='ls -lah --color=always --classify'
alias ping='grc --colour=auto ping'
alias up='sudo apt upgrade'
alias upd='sudo apt-get update'
alias CR='crontab -u daffin -e'
alias dos2unix='recode dos/CR-LF..l1'
alias unix2win='recode l1..windows-1250'
alias unix2dos='recode l1..dos/CR-LF'
alias disks="sudo lsblk -e7 -d -o name,model,serial,size,serial"
alias wget='wget --content-disposition --continue --tries=0'
alias ytd='yt-dlp -v -o "%(upload_date)s %(title)s.%(ext)s" -f bv*+?ba/b --extractor-args "youtube:player_client=default,ios" -S hdr:dv,res,vcodec:av1,acodec:opus,br --sponsorblock-mark all --sponsorblock-remove "sponsor, selfpromo" --embed-thumbnail --embed-chapters --embed-metadata --embed-subs --sub-langs all'


#### DOCKER
alias dockps='docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}"'
alias dsl='docker service ls'
alias dsp='docker service ps'

## Список загруженных контейнеров в репозитории registry.enlr.ru
lsr()
{
   THE_REGISTRY=registry.enlr.ru
   CREDS=$(jq -r ".[\"auths\"][\"registry.enlr.ru\"][\"auth\"]" ~/.docker/config.json | base64 -d)
   curl -s --user $CREDS https://$THE_REGISTRY/v2/_catalog | jq -r '.["repositories"][]' | xargs -I @REPO@ curl -s --user $CREDS https://$THE_REGISTRY/v2/@REPO@/tags/list | jq -M '.["name"] + ":" + .["tags"][]'
}

#### SWARM
## Упрощённый вход в контейнер. Пример: de bash postgres, de sh postgres
de()
{
    docker exec -it $(docker ps -f name=$2.1 -q| head -n1) $1
}

## Смотрим логи конетйнера. Пример: dl nextcloud
dl()
{
    docker logs -f $(docker ps -f name=$1.1 -q | head -n 1)
}

## Nextcloud occ. Пример: occ preview:pre-generate
occ()
{
    docker exec --user www-data -t $(docker ps -f name=nextcloud.1 -q | head -n 1) php occ $1
}
####

## Узнаем IP контейнеров
docker-ips() 
{
    docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
}

## Узнаём свой внешний IP
myip ()
{
    links -dump http://checkip.dyndns.org/ | awk '{ print $4 }' 
}

## Узнаём свой локальный IP
localip ()
{
    ip route get 1.1.1.1 | grep -oP 'src \K\S+'
}

#### UTILS
## Распаковка архивов
extract () {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2) tar xvjf $1   ;;
            *.tar.gz)  tar xvzf $1   ;;
            *.bz2)     bunzip2 $1    ;;
            *.rar)     unrar x $1    ;;
            *.gz)      gunzip $1     ;;
            *.tar)     tar xvf $1    ;;
            *.tbz2)    tar xvjf $1   ;;
            *.tgz)     tar xvzf $1   ;;
            *.zip)     unzip $1      ;;
            *.Z)       uncompress $1 ;;
            *.7z)      7z x $1       ;;
            *)         echo "'$1' cannot be extracted via >extract<" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}
## Запаковка архивов
pk() {
    if [ "$1" ] ; then
        TYPE="$1"
        shift
        case "$TYPE" in
            tbz) tar cjvf $2.tar.bz2 $@   ;;
            tgz) tar czvf $2.tar.gz $@    ;;
            tar) tar cpvf $2.tar $@       ;;
            bz2) bzip $@                  ;;
            gz)  gzip -c -9 -n $@ > $2.gz ;;
            zip) zip -r $2.zip $@         ;;
            7z)  7z a $2.7z $@            ;;
            *) echo "'$TYPE' не может быть упакован с помощью pk()" ;;
        esac
    else
        echo "'$1' не является поддерживаемым файлом"
    fi
}
nano ~/.inputrc
# To see a code a key makes, try CTRL+V <key> to get a code. Then replace ^[ with \e:
# ^[[3~ becomes "\e[3~": delete-char, for example. CTRL+V does not always work.

"\e[A": history-search-backward 
"\e[B": history-search-forward
set enable-bracketed-paste on
set show-all-if-ambiguous on
set completion-ignore-case on

# fix home/end keys on some systems
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[7~": beginning-of-line
"\e[8~": end-of-line
"\eOH": beginning-of-line
"\eOF": end-of-line
"\e[H": beginning-of-line
"\e[F": end-of-line

# fix delete key
# http://superuser.com/questions/93153/inputrc-settings-delete-char-and-keybindings-not-working
DEL: delete-char
"\e[3~": delete-char

# pageup (ok)
"\e[5~": history-search-backward

# pagedown (ok)
"\e[6~": history-search-forward

# do not make noise
set bell-style none

# ALT+right/left for emacs-style word skipping
"\e[1;3C": forward-word
"\e[1;3D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
"\eOC": forward-word
"\eOD": backward-word

# no control characters on screen
set echo-control-characters off

# F12: fg
# job control: pause/break is to background a job, make F12 restore it to the
# foreground.
"\e[24~":"\C-k \C-u fg\n"
# \C-k \C-u = clear line
# Find escape code in bash with CTRL+V <key>
# Then replace ^[ with \e
# You can also create a key binding that will execute something without
# disturbing the current command line.  bind -x '"\eW":"who"'
# http://stackoverflow.com/questions/4200800/in-bash-how-do-i-bind-a-function-key-to-a-command

# Launch FZF -> vim
"\C-p":"\C-k \C-u vimfzf\n"

# sudo-ize command
"\C-s":"\C-asudo \C-e"
nano ~/.dir_colors
# Exact Solarized Dark color theme for the color GNU ls utility.
# Designed for dircolors (GNU coreutils) 5.97
#
# This simple theme was simultaneously designed for these terminal color schemes:
# - Solarized dark  (best)
# - Solarized light
# - default dark
# - default light
# with a slight optimization for Solarized Dark.
#
# How the colors were selected:
# - Terminal emulators often have an option typically enabled by default that makes
#   bold a different color.  It is important to leave this option enabled so that
#   you can access the entire 16-color Solarized palette, and not just 8 colors.
# - We favor universality over a greater number of colors.  So we limit the number
#   of colors so that this theme will work out of the box in all terminals,
#   Solarized or not, dark or light.
# - We choose to have the following category of files:
#   NORMAL & FILE, DIR, LINK, EXEC and
#   editable text including source, unimportant text, binary docs & multimedia source
#   files, viewable multimedia, archived/compressed, and unimportant non-text
# - For uniqueness, we stay away from the Solarized foreground colors are -- either
#   base00 (brightyellow) or base0 (brighblue).  However, they can be used if
#   you know what the bg/fg colors of your terminal are, in order to optimize the display.
# - 3 different options are provided: universal, solarized dark, and solarized light.
#   The only difference between the universal scheme and one that's optimized for
#   dark/light is the color of "unimportant" files, which should blend more with the
#   background
# - We note that blue is the hardest color to see on dark bg and yellow is the hardest
#   color to see on light bg (with blue being particularly bad).  So we choose yellow
#   for multimedia files which are usually accessed in a GUI folder browser anyway.
#   And blue is kept for custom use of this scheme's user.
# - See table below to see the assignments.


# Insatllation instructions:
# This file goes in the /etc directory, and must be world readable.
# You can copy this file to .dir_colors in your $HOME directory to override
# the system defaults.

# COLOR needs one of these arguments: 'tty' colorizes output to ttys, but not
# pipes. 'all' adds color characters to all output. 'none' shuts colorization
# off.
COLOR tty

# Below, there should be one TERM entry for each termtype that is colorizable
TERM ansi
TERM color_xterm
TERM color-xterm
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM con80x30
TERM con80x43
TERM con80x50
TERM con80x60
TERM cons25
TERM console
TERM cygwin
TERM dtterm
TERM Eterm
TERM eterm-color
TERM gnome
TERM gnome-256color
TERM jfbterm
TERM konsole
TERM kterm
TERM linux
TERM linux-c
TERM mach-color
TERM mlterm
TERM nxterm
TERM putty
TERM rxvt
TERM rxvt-256color
TERM rxvt-cygwin
TERM rxvt-cygwin-native
TERM rxvt-unicode
TERM rxvt-unicode256
TERM rxvt-unicode-256color
TERM screen
TERM screen-256color
TERM screen-256color-bce
TERM screen-bce
TERM screen.linux
TERM screen-w
TERM vt100
TERM xterm
TERM xterm-16color
TERM xterm-256color
TERM xterm-88color
TERM xterm-color
TERM xterm-debian
TERM xterm-kitty
TERM screen-256color
TERM tmux-256color

# EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output)
EIGHTBIT 1

#############################################################################
# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
#
# Attribute codes: 
#   00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
#   30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
#   40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#
# NOTES:
# - See http://www.oreilly.com/catalog/wdnut/excerpt/color_names.html
# - Color combinations
#   ANSI Color code       Solarized  Notes                Universal             SolDark              SolLight
#   ~~~~~~~~~~~~~~~       ~~~~~~~~~  ~~~~~                ~~~~~~~~~             ~~~~~~~              ~~~~~~~~
#   00    none                                            NORMAL, FILE          <SAME>               <SAME>
#   30    black           base02                                                
#   01;30 bright black    base03     bg of SolDark                                                                         
#   31    red             red                             docs & mm src         <SAME>               <SAME>
#   01;31 bright red      orange                          EXEC                  <SAME>               <SAME>
#   32    green           green                           editable text         <SAME>               <SAME>
#   01;32 bright green    base01                          unimportant text      <SAME>
#   33    yellow          yellow     unclear in light bg  multimedia            <SAME>               <SAME>
#   01;33 bright yellow   base00     fg of SolLight                             unimportant non-text
#   34    blue            blue       unclear in dark bg   user customized       <SAME>               <SAME>
#   01;34 bright blue     base0      fg in SolDark                                                   unimportant text
#   35    magenta         magenta                         LINK                  <SAME>               <SAME>
#   01;35 bright magenta  violet                          archive/compressed    <SAME>               <SAME>
#   36    cyan            cyan                            DIR                   <SAME>               <SAME>
#   01;36 bright cyan     base1                           unimportant non-text                       <SAME>
#   37    white           base2                                                                      
#   01;37 bright white    base3      bg in SolLight                                                                        
#   05;37;41                         unclear in Putty dark


### By file type

# global default
NORMAL 00
# normal file
FILE 00
# directory
DIR 36
# symbolic link
LINK 35

# pipe, socket, block device, character device (blue bg)
FIFO 30;44
SOCK 35;44
DOOR 35;44 # Solaris 2.5 and later
BLK  33;44
CHR  37;44


#############################################################################
### By file attributes

# Orphaned symlinks (blinking white on red)
# Blink may or may not work (works on iTerm dark or light, and Putty dark)
ORPHAN  05;37;41
# ... and the files that orphaned symlinks point to (blinking white on red)
MISSING 05;37;41

# files with execute permission
EXEC 01;31  # Unix
.cmd 01;31  # Win
.exe 01;31  # Win
.com 01;31  # Win
.bat 01;31  # Win
.reg 01;31  # Win
.app 01;31  # OSX

#############################################################################
### By extension

# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')

### Text formats

# Text that we can edit with a regular editor
.txt 32
.org 32
.md 32
.mkd 32

# Source text
.h 32
.c 32
.C 32
.cc 32
.cxx 32
.objc 32
.sh 32
.csh 32
.zsh 32
.el 32
.vim 32
.java 32
.pl 32
.pm 32
.py 32
.rb 32
.hs 32
.php 32
.htm 32
.html 32
.shtml 32
.xml 32
.rdf 32
.css 32
.js 32
.man 32
.0 32
.1 32
.2 32
.3 32
.4 32
.5 32
.6 32
.7 32
.8 32
.9 32
.l 32
.n 32
.p 32
.pod 32
.tex 32

### Multimedia formats

# Image
.bmp 33
.cgm 33
.dl 33
.dvi 33
.emf 33
.eps 33
.gif 33
.jpeg 33
.jpg 33
.JPG 33
.mng 33
.pbm 33
.pcx 33
.pdf 33
.pgm 33
.png 33
.ppm 33
.pps 33
.ppsx 33
.ps 33
.svg 33
.svgz 33
.tga 33
.tif 33
.tiff 33
.xbm 33
.xcf 33
.xpm 33
.xwd 33
.xwd 33
.yuv 33

# Audio
.aac 33
.au  33
.flac 33
.mid 33
.midi 33
.mka 33
.mp3 33
.mpa 33
.mpeg 33
.mpg 33
.ogg  33
.ra 33
.wav 33

# Video
.anx 33
.asf 33
.avi 33
.axv 33
.flc 33
.fli 33
.flv 33
.gl 33
.m2v 33
.m4v 33
.mkv 33
.mov 33
.mp4 33
.mp4v 33
.mpeg 33
.mpg 33
.nuv 33
.ogm 33
.ogv 33
.ogx 33
.qt 33
.rm 33
.rmvb 33
.swf 33
.vob 33
.wmv 33

### Misc

# Binary document formats and multimedia source
.doc 31
.docx 31
.rtf 31
.dot 31
.dotx 31
.xls 31
.xlsx 31
.ppt 31
.pptx 31
.fla 31
.psd 31

# Archives, compressed
.7z   1;35
.apk  1;35
.arj  1;35
.bin  1;35
.bz   1;35
.bz2  1;35
.cab  1;35  # Win
.deb  1;35
.dmg  1;35  # OSX
.gem  1;35
.gz   1;35
.iso  1;35
.jar  1;35
.msi  1;35  # Win
.rar  1;35
.rpm  1;35
.tar  1;35
.tbz  1;35
.tbz2 1;35
.tgz  1;35
.tx   1;35
.war  1;35
.xpi  1;35
.xz   1;35
.z    1;35
.Z    1;35
.zip  1;35

# For testing
.ANSI-30-black 30
.ANSI-01;30-brblack 01;30
.ANSI-31-red 31
.ANSI-01;31-brred 01;31
.ANSI-32-green 32
.ANSI-01;32-brgreen 01;32
.ANSI-33-yellow 33
.ANSI-01;33-bryellow 01;33
.ANSI-34-blue 34
.ANSI-01;34-brblue 01;34
.ANSI-35-magenta 35
.ANSI-01;35-brmagenta 01;35
.ANSI-36-cyan 36
.ANSI-01;36-brcyan 01;36
.ANSI-37-white 37
.ANSI-01;37-brwhite 01;37

#############################################################################
# Your customizations

# Unimportant text files
# For universal scheme, use brightgreen 01;32
# For optimal on light bg (but too prominent on dark bg), use white 01;34
.log 01;32
*~ 01;32
*# 01;32
#.log 01;34
#*~ 01;34
#*# 01;34

# Unimportant non-text files
# For universal scheme, use brightcyan 01;36
# For optimal on dark bg (but too prominent on light bg), change to 01;33
#.bak 01;36
#.BAK 01;36
#.old 01;36
#.OLD 01;36
#.org_archive 01;36
#.off 01;36
#.OFF 01;36
#.dist 01;36
#.DIST 01;36
#.orig 01;36
#.ORIG 01;36
#.swp 01;36
#.swo 01;36
#*,v 01;36
.bak 01;33
.BAK 01;33
.old 01;33
.OLD 01;33
.org_archive 01;33
.off 01;33
.OFF 01;33
.dist 01;33
.DIST 01;33
.orig 01;33
.ORIG 01;33
.swp 01;33
.swo 01;33
*,v 01;33

# The brightmagenta (Solarized: purple) color is free for you to use for your
# custom file type
.gpg 34
.gpg 34
.pgp 34
.asc 34
.3des 34
.aes 34
.enc 34
К началу