zsh/65-scripts.zsh

104 lines
3.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Обновление конфигурации zsh, менджера zcomet и плагинов
zu() {
git -C ~/.config/zsh pull && zcomet self-update && zcomet update
}
ch() {
curl -s "https://cheat.sh/$1" | less -R
}
exf() {
case "$1" in
*.tar.bz2) tar xjf "$1" ;;
*.tar.gz) tar xzf "$1" ;;
*.tar.xz) tar xJf "$1" ;;
*.tbz2) tar xjf "$1" ;;
*.tgz) tar xzf "$1" ;;
*.tar) tar xf "$1" ;;
*.zip) unzip "$1" ;;
*.7z) 7z x "$1" ;;
*.iso) 7z x "$1" ;;
*.rar) unrar x "$1" ;;
*) echo "'$1' cannot be extracted" ;;
esac
}
exfl() {
for F in "$@"
do
if [ -f "$F" ]; then
exf "$F"
else
echo "'$F' is not a valid file"
fi
done
}
exd() {
case "$1" in
*.tar.bz2) b=${1%.tar.bz2}; mkdir -p "$b">/dev/null; tar xjf "$1" -C "$b" ;;
*.tar.gz) b=${1%.tar.gz}; mkdir -p "$b">/dev/null; tar xzf "$1" -C "$b" ;;
*.tar.xz) b=${1%.tar.xz}; mkdir -p "$b">/dev/null; tar xJf "$1" -C "$b" ;;
*.tbz2) b=${1%.tbz2}; mkdir -p "$b">/dev/null; tar xjf "$1" -C "$b" ;;
*.tgz) b=${1%.tgz}; mkdir -p "$b">/dev/null; tar xzf "$1" -C "$b" ;;
*.tar) b=${1%.tar}; mkdir -p "$b">/dev/null; tar xf "$1" -C "$b" ;;
*.zip) b=${1%.zip}; unzip "$1" -d "$b" ;;
*.7z) b=${1%.7z}; 7z x -o"$b" "$1" ;;
*.iso) b=${1%.iso}; 7z x -o"$b" "$1" ;;
*.rar) b=${1%.rar}; rar x "$1" "$b" ;;
*) echo "'$1' cannot be extracted" ;;
esac
}
exdl() {
for F in "$@"
do
if [ -f "$F" ]; then
exd "$F"
else
echo "'$F' is not a valid file"
fi
done
}
psgrep() {
ps aux | grep "${1:-.}" | grep -v grep
}
# Kills any process that matches a regexp passed to it
killit() {
ps aux | grep -v "grep" | grep "$@" | awk '{print $2}' | xargs sudo kill
}
# gather external ip address
geteip() {
curl -s -S -4 https://icanhazip.com
curl -s -S -6 https://icanhazip.com
}
# determine local IP address(es)
getip() {
if (( ${+commands[ip]} )); then
ip addr | awk '/inet /{print $2}' | command grep -v 127.0.0.1
else
ifconfig | awk '/inet /{print $2}' | command grep -v 127.0.0.1
fi
}
# Настройка mc для работы в терминале kitty
# Необходимо закрыть все экземпляры mc для текущего пользователя
# При вызове функции с параметром -f текущие настройки клавиш
# для работы mc в терминале kitty будут перезаписаны
mc-kitty-add() {
local mc_cfg="${HOME}/.config/mc/ini"
local mc_term="${ZDOTDIR}/terminfo/mc-kitty.ini"
[[ "x$1" == "x-f" ]] && sed -i '/\[terminal:xterm-kitty\]/,/^$/{d}' "${mc_cfg}"
if [ -w "${mc_cfg}" -a -r "${mc_term}" ]; then
if ! grep -qF "[terminal:xterm-kitty]" "${mc_cfg}" ; then
cat "${mc_term}" >> "${mc_cfg}"
fi
fi
}