chore: move rarely used zsh functions to files
This commit is contained in:
parent
dd7123f98a
commit
3aa127e7e6
@ -20,4 +20,5 @@ docker:.docker/cli-plugins
|
||||
ipython:.ipython/profile_default/ipython_config.py
|
||||
gdb:.config/gdb
|
||||
sandbox:
|
||||
utils: .local/bin/myip .local/bin/genpass .local/bin/gensalt .local/bin/django-create-project .local/bin/mirror-site .local/bin/split-file .local/bin/extract .local/bin/destroy
|
||||
all:%less %t %tmux %zsh %nvim %git"
|
||||
@ -57,9 +57,6 @@ alias c='clear'
|
||||
alias h='history 0'
|
||||
alias j='jobs -l'
|
||||
|
||||
# utils
|
||||
alias genpass="openssl rand -base64 12"
|
||||
alias gensalt="dd if=/dev/urandom count=16 2>/dev/null | sha256sum | head -c 64"
|
||||
|
||||
if command -v colordiff &>/dev/null; then
|
||||
alias diff='colordiff'
|
||||
@ -81,8 +78,6 @@ alias svi="sudo --preserve-env nvim"
|
||||
# net
|
||||
alias ports='ss -tlnp'
|
||||
alias wget='wget -c'
|
||||
# alias myip='curl ipinfo.io/ip'
|
||||
alias myip='dig +short myip.opendns.com @resolver1.opendns.com'
|
||||
alias ip='ip -c'
|
||||
alias fastping='ping -c 100 -i 0.1'
|
||||
|
||||
|
||||
@ -1,29 +1,5 @@
|
||||
# vim: ft=zsh
|
||||
|
||||
destroy() {
|
||||
local -r filename="${1}"
|
||||
|
||||
if [[ ! -f "${filename}" ]]; then
|
||||
echo "destroy: File '${filename}' not found" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local filesize
|
||||
filesize="$(du -hs "${filename}" | awk '{printf $1}')"
|
||||
readonly filesize
|
||||
|
||||
echo -n "Sure want to destroy file '${filename}' with size ${filesize} [y/N] "
|
||||
|
||||
local response
|
||||
read -r response
|
||||
readonly response
|
||||
if [[ ! "${response}" == [yY] ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
shred -zun 3 "${filename}"
|
||||
}
|
||||
|
||||
py() {
|
||||
if [[ -z "$@" && -x "$(command -v ipython 2>/dev/null)" ]]; then
|
||||
ipython -i -c "q = exit"
|
||||
@ -65,46 +41,6 @@ va() {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
extract() (
|
||||
if [ -z "${1}" ]; then
|
||||
echo "extract: error: usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
|
||||
return 2
|
||||
fi
|
||||
|
||||
if ! [ -f "${1}" ]; then
|
||||
echo "extract: error: '${1}' file does not exist" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local -r name="${1%%.*}" # removes extension from filename
|
||||
if [ -e "${name}" ]; then
|
||||
echo "extract: error: '${name}' exists" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir "${name}" && cd "${name}" || return 1
|
||||
|
||||
case $1 in
|
||||
*.tar.bz2) tar xjf ../"${1}" ;;
|
||||
*.tar.gz) tar xzf ../"${1}" ;;
|
||||
*.tar.xz) tar xJf ../"${1}" ;;
|
||||
*.lzma) unlzma ../"${1}" ;;
|
||||
*.bz2) bunzip2 ../"${1}" ;;
|
||||
*.rar) unrar x -ad ../"${1}" ;;
|
||||
*.gz) gunzip ../"${1}" ;;
|
||||
*.tar) tar xf ../"${1}" ;;
|
||||
*.tbz2) tar xjf ../"${1}" ;;
|
||||
*.tgz) tar xzf ../"${1}" ;;
|
||||
*.zip) unzip ../"${1}" ;;
|
||||
*.Z) uncompress ../"${1}" ;;
|
||||
*.7z) 7z x ../"${1}" ;;
|
||||
*.xz) unxz ../"${1}" ;;
|
||||
*.exe) cabextract ../"${1}" ;;
|
||||
*) echo "extract: error: '${1}' - unknown archive method" >&2 ;;
|
||||
esac
|
||||
)
|
||||
|
||||
mcd() {
|
||||
if [ -z "${1}" ]; then
|
||||
cd "$(mktemp -td "${USER:-user}.XXXX")"
|
||||
@ -118,19 +54,6 @@ open() {
|
||||
nohup xdg-open "${1}" 1>/dev/null 2>&1 &
|
||||
}
|
||||
|
||||
split-file() {
|
||||
if [[ ! -e "${1}" ]]; then
|
||||
echo "file '${1}' not found" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local -r size="${2:-1G}"
|
||||
|
||||
mkdir "${1}.splitted"
|
||||
cd "${1}.splitted"
|
||||
split -d -b "${size}" "../${1}"
|
||||
}
|
||||
|
||||
json() {
|
||||
if [ -t 0 ]; then
|
||||
python -m json.tool <<< "$*"
|
||||
@ -139,21 +62,6 @@ json() {
|
||||
fi
|
||||
}
|
||||
|
||||
rmt() {
|
||||
local -r trash="${TRASH:-"${HOME}/.trash"}"
|
||||
|
||||
local filename
|
||||
for filename in "$@"
|
||||
do
|
||||
local filename_out_path
|
||||
filename_out_path="${trash}$(realpath "${filename}")"
|
||||
readonly filename_out_path
|
||||
|
||||
mkdir -p "$(dirname "${filename_out_path}")"
|
||||
mv "${filename}" "${filename_out_path}_$(date +%s)"
|
||||
done
|
||||
}
|
||||
|
||||
showtips() {
|
||||
local -r tips_dir="${HOME}/.tips"
|
||||
|
||||
@ -171,23 +79,6 @@ showtips() {
|
||||
return 0
|
||||
}
|
||||
|
||||
most-often-commands() {
|
||||
history 0 | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn
|
||||
}
|
||||
|
||||
django-create-project() (
|
||||
set -ue
|
||||
local -r project_name="${1}"
|
||||
|
||||
mkdir "${project_name}"
|
||||
cd "${project_name}"
|
||||
python3 -m virtualenv venv
|
||||
. venv/bin/activate
|
||||
pip install django
|
||||
django-admin startproject core .
|
||||
git init
|
||||
)
|
||||
|
||||
cleanup-directory() {
|
||||
local -r directory="${1}"
|
||||
|
||||
@ -242,33 +133,6 @@ bak() {
|
||||
done
|
||||
}
|
||||
|
||||
mirror-site() (
|
||||
set -eu
|
||||
|
||||
local -r name="${1}"; shift
|
||||
|
||||
mkdir -p "${name}" && cd "${name}"
|
||||
|
||||
local -r user_agent="Mozilla/5.0 ..."
|
||||
wget \
|
||||
--page-requisites \
|
||||
--convert-links \
|
||||
--adjust-extension \
|
||||
--restrict-file-names=ascii \
|
||||
--span-hosts \
|
||||
--random-wait \
|
||||
--execute robots=off \
|
||||
--recursive \
|
||||
--timestamping \
|
||||
-l inf \
|
||||
--no-remove-listing \
|
||||
--no-parent \
|
||||
--user-agent "${user_agent}" \
|
||||
--reject '*.woff*,*.ttf,*.eot,*.js' \
|
||||
--tries 10 \
|
||||
$@
|
||||
)
|
||||
|
||||
sha() {
|
||||
if [ -v 2 ]; then
|
||||
shasum -a 256 "${@}"
|
||||
|
||||
23
home/user/.local/bin/destroy
Executable file
23
home/user/.local/bin/destroy
Executable file
@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
readonly filename="${1}"
|
||||
|
||||
if [ ! -f "${filename}" ]; then
|
||||
echo "destroy: File '${filename}' not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
filesize="$(du -hs "${filename}" | awk '{printf $1}')"
|
||||
readonly filesize
|
||||
|
||||
printf "Sure want to destroy file '%s' with size %s [y/N] " "${filename}" "${filesize}"
|
||||
|
||||
read -r response
|
||||
readonly response
|
||||
if [ ! "${response}" = "y" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shred -zun 3 "${filename}"
|
||||
15
home/user/.local/bin/django-create-project
Executable file
15
home/user/.local/bin/django-create-project
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
|
||||
set -ue
|
||||
|
||||
|
||||
readonly project_name="${1}"
|
||||
|
||||
mkdir "${project_name}"
|
||||
cd "${project_name}"
|
||||
python3 -m virtualenv venv
|
||||
. venv/bin/activate
|
||||
pip install django
|
||||
django-admin startproject core .
|
||||
git init
|
||||
41
home/user/.local/bin/extract
Executable file
41
home/user/.local/bin/extract
Executable file
@ -0,0 +1,41 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
|
||||
if [ -z "${1}" ]; then
|
||||
echo "extract: error: usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if ! [ -f "${1}" ]; then
|
||||
echo "extract: error: '${1}' file does not exist" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
readonly name="${1%%.*}" # removes extension from filename
|
||||
if [ -e "${name}" ]; then
|
||||
echo "extract: error: '${name}' exists" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir "${name}" && cd "${name}" || exit 1
|
||||
|
||||
case "${1}" in
|
||||
*.tar.bz2) tar xjf ../"${1}" ;;
|
||||
*.tar.gz) tar xzf ../"${1}" ;;
|
||||
*.tar.xz) tar xJf ../"${1}" ;;
|
||||
*.lzma) unlzma ../"${1}" ;;
|
||||
*.bz2) bunzip2 ../"${1}" ;;
|
||||
*.rar) unrar x -ad ../"${1}" ;;
|
||||
*.gz) gunzip ../"${1}" ;;
|
||||
*.tar) tar xf ../"${1}" ;;
|
||||
*.tbz2) tar xjf ../"${1}" ;;
|
||||
*.tgz) tar xzf ../"${1}" ;;
|
||||
*.zip) unzip ../"${1}" ;;
|
||||
*.Z) uncompress ../"${1}" ;;
|
||||
*.7z) 7z x ../"${1}" ;;
|
||||
*.xz) unxz ../"${1}" ;;
|
||||
*.exe) cabextract ../"${1}" ;;
|
||||
*) echo "extract: error: '${1}' - unknown archive method" >&2 ;;
|
||||
esac
|
||||
5
home/user/.local/bin/genpass
Executable file
5
home/user/.local/bin/genpass
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ue
|
||||
|
||||
openssl rand -base64 12
|
||||
5
home/user/.local/bin/gensalt
Executable file
5
home/user/.local/bin/gensalt
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ue
|
||||
|
||||
dd if=/dev/urandom count=16 2>/dev/null | sha256sum | head -c 64
|
||||
26
home/user/.local/bin/mirror-site
Executable file
26
home/user/.local/bin/mirror-site
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
readonly name="${1}"; shift
|
||||
|
||||
mkdir -p "${name}" && cd "${name}"
|
||||
|
||||
readonly user_agent="Mozilla/5.0 ..."
|
||||
wget \
|
||||
--page-requisites \
|
||||
--convert-links \
|
||||
--adjust-extension \
|
||||
--restrict-file-names=ascii \
|
||||
--span-hosts \
|
||||
--random-wait \
|
||||
--execute robots=off \
|
||||
--recursive \
|
||||
--timestamping \
|
||||
-l inf \
|
||||
--no-remove-listing \
|
||||
--no-parent \
|
||||
--user-agent "${user_agent}" \
|
||||
--reject '*.woff*,*.ttf,*.eot,*.js' \
|
||||
--tries 10 \
|
||||
"$@"
|
||||
6
home/user/.local/bin/myip
Executable file
6
home/user/.local/bin/myip
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
|
||||
curl ipinfo.io/ip
|
||||
echo
|
||||
dig +short myip.opendns.com @resolver1.opendns.com
|
||||
15
home/user/.local/bin/split-file
Executable file
15
home/user/.local/bin/split-file
Executable file
@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
|
||||
if [ ! -e "${1}" ]; then
|
||||
echo "file '${1}' not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
readonly size="${2:-1G}"
|
||||
|
||||
mkdir "${1}.splitted"
|
||||
cd "${1}.splitted"
|
||||
split -d -b "${size}" "../${1}"
|
||||
Loading…
x
Reference in New Issue
Block a user