Dotfiles.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

468 lines
15 KiB

12 years ago
#!/bin/bash ####################################################################
12 years ago
################################################################################
#{{{ Псевдонимы
################################################################################
alias ~='cd ~' #noindex
alias ..='cd ..' #noindex
alias .-='cd -' #noindex
alias pd="pushd" #noindex
alias po="popd" #noindex
#- Удаление, перемещение и копирование с подтверждением
#+ Строка прогресса: http://beatex.org/web/advancedcopy.html
alias mv='mv -g -i -v' #noindex
alias cp='cp -g -i -v -r' #noindex
12 years ago
alias rm="rm -i -v" #noindex
alias rmdir="rmdir -v" #noindex
#- Алиасы для стандартных команд
alias gcc="gcc -Os -Wextra -Wall" #noindex
alias g++="g++ -Os -Wall" #noindex
alias echo="echo -e" #noindex
alias less="less -R" #noindex
alias ls='ls -lGhpX --color=always --group-directories-first -v' #noindex
alias lsl='ls -L' #noindex
alias lst='ls -al --time-style=+%D | grep $(\date +%D)' #noindex
12 years ago
alias lss='\ls --format=single-column' #noindex
alias nl="nl -b a" #noindex
alias df='df -hT' #noindex
alias dfc='dfc -t ext4,fuseblk -w' #noindex
12 years ago
alias du='du -hs' #noindex
alias free="free -m" #noindex
alias wget='wget -c -T 5' #noindex
alias ps="ps -aux" #noindex
alias grep='grep -E -i --color=auto' #noindex
12 years ago
alias tree="tree -CAFa" #noindex
alias crontab_i="crontab $CRON" #noindex
alias crontab_e="$EDITOR $CRON" #noindex
alias dmenu="dmenu -fn '-*-fixed-*-*-*-*-15-*-*-*-*-*-*-*'" #noindex
alias pstree="pstree -U -h" #noindex
alias mkdir="mkdir -p -v" #noindex
alias j="jobs -l" #noindex
alias dirs="dirs -v" #noindex
alias ping="pingp --nolegend" #noindex
alias gq="geeqie . &" #noindex
alias emerge="emerge --ask" #noindex
alias xlock="i3lock -i $SHELLRC/etc/wm/locker.png" #noindex
12 years ago
#- Замена стандартных путей для конфигурационных файлов
alias mpd="mpd $SHELLRC/etc/media/mpd/mpd.conf" #noindex
alias mpdr="\mpd $SHELLRC/etc/media/mpd/mpd_remote.conf" #noindex
alias vim="vim -N -i $SHELLRC/var/vim/viminfo -p $*" #noindex
12 years ago
alias mutt="mutt -F $SHELLRC/etc/mail/mutt/muttrc && echo "0" > $MD/new" #noindex
alias screen="TERM=rxvt-256color screen" #noindex
alias figlet="figlet -f $SHELLRC/etc/soft/figlet/fonts/standard.flf" #noindex
alias cdargs="cdargs -b -f $SHELLRC/etc/soft/cdargs/cdargs -o $SHELLRC/etc/soft/cdargs/cdargsresult" #noindex
alias zathura="nh zathura" #noindex
alias z="nh zathura" #noindex
alias kz="killall zathura" #noindex
12 years ago
alias sendemail="sendemail -l $LOGDIR/sendemail" #noindex
alias g=git #noindex
alias startx="xinit -- /usr/bin/X" #noindex
alias lftp="LFTP_HOME=$SHELLRC/etc/net/lftp lftp" #noindex
12 years ago
alias fm="PAGER=autoex fm" #noindex
12 years ago
if [ $UID -eq 0 ]; then
alias mc="TERM=xterm-256color mc -S modarin256root"
12 years ago
else
alias mc="TERM=xterm-256color mc -S modarin256"
12 years ago
alias htop="htop -u $(whoami)"
fi
#}}} ###########################################################################
#{{{ \033[00m\n\b------<Bash>\n
################################################################################
#- Подсветка текущего дня в календаре
function cal() { #noindex
[ -z "$1" ] && command cal -m | clr "$(\date +%_d)" || command cal -m $*
12 years ago
}
#- Запуск программ без привязки к сессии
nh() {
nohup "$@" &>/dev/null &
}
#- Правка псевдонимов в Vim
alias ealias="$EDITOR $ALIASES" #noindex
12 years ago
#- Перезагрузка конфигов баша
alias reload=". ~/.bashrc" #noindex
#- Перезагрузка конфигов X.org
alias reloadx="xrdb -merge ~/.Xdefaults" #noindex
12 years ago
#- Выход из сеанса
alias :q="exit" #noindex
12 years ago
#- ls с цифровым видом прав
alias lls="ls -l | sed 's/--x/1/g; s/-w-/2/g; s/-wx/3/g; s/r--/4/g;
s/r-x/5/g; s/rw-/6/g; s/rwx/7/g; s/---/0/g'"
#- История bash
h() { [ -z "$1" ] && history || history | grep "$1"; } #noindex
12 years ago
#Переназначение функции, вызываемой неизвестной командой
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 $@ | \
sed "y/йцукенгшщзхъфывапролджэячсмитьбю\.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,/qwertyuiop\[\]asdfghjkl;\'zxcvbnm,\.\/QWERTYUIOP\{\}ASDFGHJKL:\"ZXCVBNM<>\?/")"
echo "$red[$@] -> $green[$ex]$rstc"
bash --rcfile ~/.bashrc -c "$ex"
12 years ago
else
echo >&2 "$redКоманда ${green}${1}${red} не найдена.$rstc"
fi
fi
}
#- Дата
function date() { #noindex
11 years ago
if [ -z "$1" ]; then
command date '+%A, %d %B %Y, %H:%M'
else
command date "$@"
fi
}
12 years ago
#- Список функций и псевдонимов
:h() { #noindex
12 years ago
printf "$white
-----------------------[ Функции и псевдонимы ]-----------------------$rstc\n"
for file in ${HELPSRC[@]}; {
for i in $(awk '/\w\(\)|^alias|^#\{\{\{ / && !/#noindex/ {print NR"\n"}' $file); {
printf "$blue\t%-17s$rstc%s\n" \
"$(echo $(sed "s/=/ /g; /alias \|()\|#{{{ \| .*/ s///g; "$i"q;d" $file))" \
"$(sed "/#\|}}}/ s///g; "$[--i]"q;d" $file)";
12 years ago
}
}
printf "$white
----------------------------------------------------------------------$rstc\n\n"
}
#- Бэкап настроек
b_back() { tar cvpzf "./Bash_`\date +%d-%m-%Y.%T`".tgz $SHELLRC; }
#- Цветовые коды консоли
colors() {
for i in {000..125}; {
printf "\033[${i}m${i}\e[0m "
} | fmt -w 130
12 years ago
}
#- Самые используемые команды [-u -- уникальные]
toph() {
case "$1" in
-u) history | cut -d ' ' -f 6- | sort | uniq -c | sort -rn | head -n 30;;
* ) history | awk '{a[$4]++} END {for(i in a) {print a[i] " " i}}' \
| sort -rn | head -n 30 | column -t;;
esac
}
#- Форматированный вывод PATH
path() {
echo $PATH | tr ':' '\n' | nl
}
#-
alias w1="watch -n 1" #noindex
#}}} ###########################################################################
#{{{ \033[00m\n\b------<Сетевые_функции>\n
################################################################################
#- php-сервер
phps() {
php -S ${2:-localhost}:${3:-80} -t ${1:-.}
}
12 years ago
#}}} ###########################################################################
#{{{ \033[00m\n\b------<Работа_с_файлами>\n
################################################################################
#- Vim
alias :e="vim" #noindex
12 years ago
#- Закладки web-браузера
alias bookmarks="vim $SHELLRC/var/www/urls" #noindex
#- Переход в последнюю директорию vifm
vicd() { #noindex
local dst="$(command vifm --choose-dir -)"
if [ -z "$dst" ]; then
echo 'Directory picking cancelled/failed'
return 1
fi
cd "$dst"
}
function vifm() { #noindex
if [ -f ~/.vifm/lastdir ]; then
\rm ~/.vifm/lastdir
fi
# "command" prevents recursive call
TERM=xterm-256color command vifm .
if [ -f ~/.vifm/lastdir ]; then
cd "`cat ~/.vifm/lastdir`"
fi
}
#- Создание doc-файла в vim
vdoc() {
vim "$1" && libreoffice --convert-to doc --invisible "$1"
}
#- Копирование содержимого файла в буфер обмена
xc() {
cat "$@" | xclip -selection clipboard
}
12 years ago
#- Переход с поиском выше по дереву директорий
up() {
[[ "$1" == "" ]] && cd .. \
|| cd $(echo $PWD | \grep -o "^.*$1\/" \
|| (echo "$redПуть $1 не найден$rstc" >&2 && echo ".") )
}
#- koi8r -> utf8
alias KU="iconv -c -f koi8r"
#- cp1251 -> utf8
alias CU="iconv -c -f cp1251"
#- 866 -> utf8
alias 8U="iconv -c -f 866"
12 years ago
#- utf8 -> koi8r
alias UK="iconv -c -t koi8r"
#- utf8 -> cp1251
alias UC="iconv -c -t cp1251"
#- utf8 -> 866
alias U8="iconv -c -t 866"
12 years ago
#- -> utf8
alias 2U="iconv -c -t utf8"
lnt() { #noindex
ln -s "$(pwd)/$1" "$HOME/Downloads/TORRENTS/${2:-}"
}
#- Создание резервной копии файла
backup() { cp $1{,.$(\date "+%d-%m-%Y.%T").bak}; }
#- Удаление HTML-тэгов из файла ($1)
unhtml() { cat $1 | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'; }
sortf() { #noindex
mkdir -p ./Archives ; command mv *{.rar,.tar.*,.bz2,.gz,.tar,.t?z?,.zip,.7z,.tgz} ./Archives
mkdir -p ./Images ; command mv *{.jpg,.JPG,.jpeg,.bmp,.gif,.png} ./Images
mkdir -p ./Video ; command mv *{.avi,.mpg,.mp4,.dvx,.flv} ./Video
mkdir -p ./Docs ; command mv *{.doc,.docx,.odt,.pdf,.txt,.rtf,.fb2,.epub,.djv,.djvu,.chm,.html} ./Docs
mkdir -p ./Audio ; command mv *{.ogg,.mp3,.wav,.m3u,.midi,.mid,.gp?} ./Audio
mkdir -p ./TFiles ; command mv *.torrent* ./TFiles
mkdir -p ./Scripts ; command mv *{.sh,.py,.rb,.tcl} ./Scripts
mkdir -p ./Vim ; command mv *{.vim,.vba} ./Vim
12 years ago
} 2>&-
alias tt=ctorrent #noindex
9 years ago
#- Переименовывание torrent-файла
ttr() {
echo mv -i -v \"$1\" \"tt_$(dumptorrent -b "$1" \
9 years ago
| cut -d ':' -f 2 \
| sed 's/^ *//').torrent\" \
| sh
}
#- type с подсветкой синтаксиса
function type() { #noindex
command type "$1" | source-highlight \
--src-lang=sh \
-f esc \
-o STDOUT \
--line-number=' ' \
--style-file=$SHELLRC/etc/soft/source-hl/default.style
echo
}
10 years ago
#- Ссылка на книгу для чтения
toread() {
BASEDIR="$HOME/FILES/_Книги/Прочесть"
[ ! -z "$2" ] && mkdir -p "$BASEDIR/$2"
ln -s "`realpath "$1"`" "$BASEDIR/${2:-.}/$1"
10 years ago
}
#- ++less noindex
src() { vcat "$1" | less -R; }
12 years ago
#- Поиск пути к исполняемому файлу, просмотр кода функций и псевдонимов
which() { #noindex
(alias; declare -f) \
| /usr/bin/which \
--tty-only \
--read-alias \
--read-functions \
--show-tilde \
--show-dot $@
} 2>/dev/null
#- Переход в директорию файла
cdwhich() {
cd $(dirname $(/usr/bin/which $1))
}
#- Редактирование скриптов
dowhich() { #noindex
eval $1 $(/usr/bin/which $2)
}
#- Редактирование скриптов
alias vimwhich="dowhich vim" #noindex
alias nlwhich="dowhich nl" #noindex
alias catwhich="dowhich cat" #noindex
alias vcatwhich="dowhich vcat" #noindex
12 years ago
#- Список уникальных слов с количеством вхождений
wcu() {
cat "$1" | tr -cs A-Za-z\' '\n' | tr A-Z a-z | sort | uniq -c | sort -nr | nl
}
#- Выполнение команды для всех файлов: apply cmd -1 -2 @ *.file
apply() {
CMD=""
for argument in $@; {
if [ "$argument" != "@" ]; then
CMD+=" $argument"; shift
else
shift; break
fi
}
for file in "$@"; {
eval "$CMD" \""$file"\"
}
}
8 years ago
#- Список PDF-файлов
alias pdfs="find `pwd` -maxdepth 1 -name '*.pdf'" #noindex
12 years ago
#}}} ###########################################################################
#{{{ \033[00m\n\b------<Администрирование>\n
################################################################################
#- Копирование файла $1 в $SHELLRC/bin/$2
cpbin() {
cp $1 $SHELLRC/bin/$2/
}
#- Перемещение файла $1 в $SHELLRC/bin/$2
mvbin() {
mv $1 $SHELLRC/bin/$2/
}
#- Создание символической ссылки на файл $1 в $SHELLRC/bin/$2
lnbin() {
ln -s $(realpath $1) $SHELLRC/bin/$2/$1
}
#- UUID носителей
alias uuids="ls /dev/disk/by-uuid/"
#}}} ###########################################################################
#{{{ \033[00m\n\b------<Управление_сервисами_и_процессами>\n
################################################################################
#- Поиск процесса по имени
alias pgrep="pgrep -l"
#- Запуск сервиса
start() { su -c "sh /etc/init.d/$1 start"; }
12 years ago
#- Остановка сервиса
stop() { su -c "sh /etc/init.d/$1 stop"; }
12 years ago
#- Перезапуск сервиса
restart() { su -c "sh /etc/init.d/$1 restart"; }
12 years ago
#}}} ###########################################################################
#{{{ \033[00m\n\b------<Прочее>\n
12 years ago
################################################################################
#- Консольный калькулятор
9 years ago
=() { echo "$*" | bc -l; }
12 years ago
#- Подсветка выражений
clr() {
case "$1" in
-bb) sed -r -e "s/$2/`echo -e "\033"`[7;34m&`echo -e "\033"`[1;0m/g";;
-bc) sed -r -e "s/$2/`echo -e "\033"`[7;36m&`echo -e "\033"`[1;0m/g";;
-bg) sed -r -e "s/$2/`echo -e "\033"`[7;32m&`echo -e "\033"`[1;0m/g";;
-br) sed -r -e "s/$2/`echo -e "\033"`[7;31m&`echo -e "\033"`[1;0m/g";;
-by) sed -r -e "s/$2/`echo -e "\033"`[7;33m&`echo -e "\033"`[1;0m/g";;
-bm) sed -r -e "s/$2/`echo -e "\033"`[7;35m&`echo -e "\033"`[1;0m/g";;
-fo) sed -r -e "s/$2/`echo -e "\033"`[1;91m&`echo -e "\033"`[1;0m/g";;
-fb) sed -r -e "s/$2/`echo -e "\033"`[1;34m&`echo -e "\033"`[1;0m/g";;
-fc) sed -r -e "s/$2/`echo -e "\033"`[1;36m&`echo -e "\033"`[1;0m/g";;
-fg) sed -r -e "s/$2/`echo -e "\033"`[1;32m&`echo -e "\033"`[1;0m/g";;
-fr) sed -r -e "s/$2/`echo -e "\033"`[1;31m&`echo -e "\033"`[1;0m/g";;
-fy) sed -r -e "s/$2/`echo -e "\033"`[1;33m&`echo -e "\033"`[1;0m/g";;
-fm) sed -r -e "s/$2/`echo -e "\033"`[0;35m&`echo -e "\033"`[1;0m/g";;
* ) sed -e "s/$1/`echo -e "\033"`[7;31m&`echo -e "\033"`[1;0m/g";;
esac
}
12 years ago
#- Выполнение команды без цветного вывода
noc() {
rstc=""
yellow=""
blue=""
red=""
green=""
grey=""
white=""
eval "$@"
}
#- Перевод слов/выражений с сохранением слова в файл
t() {
sdcvc="sdcv --data-dir $SHELLRC/etc/soft/sdcv/dictionaries/"
if [ "$1" == "-p" ]; then
shift 1
eval $sdcvc \"$*\"
return
fi
eval $sdcvc \"$*\" | sed 's/[^ ]*\.wav//g' \
| sed 's/BrE\|NAmE/\n&/g' \
| sed '$!N; /^\(.*\)\n\1$/!P; D' \
| clr -fm '\[[^]]*\]' \
| clr -fy '=|~|[[:space:]]+[0-9a-zA-Zа-яА-Я]{1,2}\)|^[0-9]\.|^I+[[:space:]]' \
| clr -fo 'амер(иканизм|\.)?|\(US [^)]+\)|NAmE' \
| clr -fc 'BrE|via|from| f. |Word.Origin:' \
| clr -fb 'Syn\.:.[A-Z., ]+' \
| clr -bg --\>.* \
| sed "s/\&apos;/'/g"
}
alias ?=t #noindex
#- Vimwiki
alias ,ww="vim -c VimwikiIndex" #noindex
12 years ago
#- Дневник
alias ,w,w="vim -c VimwikiMakeDiaryNote" #noindex
#- Vim со списком последних файлов
alias ,m="vim -c MRU" #noindex
12 years ago
#- Загрузка текста на ix.io
alias ix="curl -F 'f:1=<-' ix.io"
#- Преобразование списка в строку
alias flat="tr '\n' ' '; echo"
12 years ago
#}}} ###########################################################################