move function to scripts
This commit is contained in:
parent
58e3a093f9
commit
f8f7831415
@ -25,5 +25,5 @@ gdb:.config/gdb
|
|||||||
sandbox:
|
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
|
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
|
||||||
chromium:.local/bin/pchromium .local/share/applications/pchromium.desktop
|
chromium:.local/bin/pchromium .local/share/applications/pchromium.desktop
|
||||||
scripts:.local/bin/httpstatus .local/bin/bb .local/bin/emoji .local/bin/mksh .local/bin/nato .local/bin/pastas .local/bin/timer .local/bin/tryna .local/bin/trynafail
|
scripts:.local/bin/httpstatus .local/bin/bb .local/bin/emoji .local/bin/mksh .local/bin/nato .local/bin/pastas .local/bin/timer .local/bin/tryna .local/bin/trynafail .local/bin/bak .local/bin/cleanup-directory .local/bin/cleanup-directory-log .local/bin/cleanup-downloads .local/bin/gobuild .local/bin/json .local/bin/mcd .local/bin/open .local/bin/py .local/bin/sha .local/bin/showtips .local/bin/weather
|
||||||
all:%less %t %note %tmux %zsh %nvim %git"
|
all:%less %t %note %tmux %zsh %nvim %git"
|
||||||
|
|||||||
@ -1,13 +1,5 @@
|
|||||||
# vim: ft=zsh
|
# vim: ft=zsh
|
||||||
|
|
||||||
py() {
|
|
||||||
if [[ -z "$@" && -x "$(command -v ipython 2>/dev/null)" ]]; then
|
|
||||||
ipython -i -c "q = exit"
|
|
||||||
else
|
|
||||||
python3 "$@"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
ve() {
|
ve() {
|
||||||
local -r venv_name="${1:-venv}"
|
local -r venv_name="${1:-venv}"
|
||||||
python3 -m venv "${venv_name}" && . "${venv_name}/bin/activate"
|
python3 -m venv "${venv_name}" && . "${venv_name}/bin/activate"
|
||||||
@ -41,146 +33,6 @@ va() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
mcd() {
|
|
||||||
local dir
|
|
||||||
|
|
||||||
if [ -z "${1}" ]; then
|
|
||||||
dir="$(mktemp -ut "${USER:-user}.XXXX")"
|
|
||||||
else
|
|
||||||
dir="${1}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
mkdir -p "${dir}" && cd "${dir}"
|
|
||||||
}
|
|
||||||
|
|
||||||
open() {
|
|
||||||
if [ ! -e "${1}" ]; then
|
|
||||||
printf 'File %s not found' "${1}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
nohup xdg-open "${1}" 1>/dev/null 2>&1 &
|
|
||||||
}
|
|
||||||
|
|
||||||
json() {
|
|
||||||
if [ -t 0 ]; then
|
|
||||||
python -m json.tool <<< "$*"
|
|
||||||
else # pipe
|
|
||||||
python -m json.tool
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
showtips() {
|
|
||||||
local -r tips_dir="${HOME}/.tips"
|
|
||||||
|
|
||||||
if [ ! -d "${tips_dir}" ]; then
|
|
||||||
mkdir "${tips_dir}" 2>/dev/null
|
|
||||||
git init "${tips_dir}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -o nullglob
|
|
||||||
local filename
|
|
||||||
for filename in "${tips_dir}"/*
|
|
||||||
do
|
|
||||||
cat "${filename}"
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup-directory() {
|
|
||||||
local -r directory="$(realpath "${1}")"
|
|
||||||
local -r age="+21" # Notation: +n => "At least n days"
|
|
||||||
|
|
||||||
if [ ! -d "${directory}" ]; then
|
|
||||||
echo "Directory '${directory}' not found" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "${DRYRUN}" ]; then
|
|
||||||
echo "Deleting files not accessed for a ${age} days:"
|
|
||||||
find "${directory}" -mindepth 1 -atime "${age}" -not -type d -not -name cleanup.log
|
|
||||||
|
|
||||||
echo "Deleting empty directories:"
|
|
||||||
find "${directory}" -mindepth 1 -type d -empty
|
|
||||||
else
|
|
||||||
echo "Deleting files not accessed for a ${age} days:"
|
|
||||||
find "${directory}" -mindepth 1 -atime "${age}" -not -type d -not -name cleanup.log -print -delete
|
|
||||||
|
|
||||||
echo "Deleting empty directories:"
|
|
||||||
find "${directory}" -mindepth 1 -type d -empty -print -delete
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup-directory-log() {
|
|
||||||
local -r directory="$(realpath "${1}")"
|
|
||||||
if [ ! -d "${directory}" ]; then
|
|
||||||
echo "Directory '${directory}' not found" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local log_file="${directory}/cleanup.log"
|
|
||||||
|
|
||||||
if [ -n "${DRYRUN}" ]; then
|
|
||||||
log_file="/dev/null"
|
|
||||||
fi
|
|
||||||
|
|
||||||
touch "${log_file}"
|
|
||||||
|
|
||||||
echo "$(date -Iseconds) : Start cleanup" >> "${log_file}"
|
|
||||||
cleanup-directory "${directory}" | tee -a "${log_file}"
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup-downloads() {
|
|
||||||
local -r downloads_directory="${XDG_DOWNLOAD_DIR}"
|
|
||||||
cleanup-directory-log "${downloads_directory}"
|
|
||||||
}
|
|
||||||
|
|
||||||
_bak() {
|
|
||||||
local -r filename="${1}"
|
|
||||||
mv "${filename}" "${filename}.bak"
|
|
||||||
}
|
|
||||||
|
|
||||||
_unbak() {
|
|
||||||
local -r filename="${1}"
|
|
||||||
local -r new_filename="${filename/%.bak/}"
|
|
||||||
|
|
||||||
if [[ -e "${new_filename}" ]]; then
|
|
||||||
echo "Filename '${new_filename}' already exists" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
mv "${filename}" "${new_filename}"
|
|
||||||
}
|
|
||||||
|
|
||||||
bak() {
|
|
||||||
local filename
|
|
||||||
for filename in "$@"; do
|
|
||||||
if [[ "${filename: -4}" = ".bak" ]]; then
|
|
||||||
_unbak "${filename}"
|
|
||||||
else
|
|
||||||
_bak "${filename}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
sha() {
|
|
||||||
if [ -v 2 ]; then
|
|
||||||
shasum -a 256 "${@}"
|
|
||||||
elif [ -v 1 ]; then
|
|
||||||
shasum -a 256 "${@}" | head -c 64
|
|
||||||
else
|
|
||||||
shasum -a 256 | head -c 64
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
weather() {
|
|
||||||
local -r city="${1}"
|
|
||||||
curl "wttr.in/${city}" 2>/dev/null | head -n -1
|
|
||||||
}
|
|
||||||
|
|
||||||
gobuild() {
|
|
||||||
go build $@ -o ./bin/ ./...
|
|
||||||
}
|
|
||||||
|
|
||||||
top-commands() {
|
top-commands() {
|
||||||
local -r num_args="${1:-1}"
|
local -r num_args="${1:-1}"
|
||||||
|
|
||||||
|
|||||||
34
home/user/.local/bin/bak
Executable file
34
home/user/.local/bin/bak
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
ends_with_bak() {
|
||||||
|
case "${1}" in
|
||||||
|
*.bak) return 0 ;;
|
||||||
|
*) return 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_bak() {
|
||||||
|
filename="${1}"
|
||||||
|
mv "${filename}" "${filename}.bak"
|
||||||
|
}
|
||||||
|
|
||||||
|
_unbak() {
|
||||||
|
filename="${1}"
|
||||||
|
new_filename="$(echo "${filename}" | sed 's/\.bak$//')"
|
||||||
|
|
||||||
|
if [ -e "${new_filename}" ]; then
|
||||||
|
echo "Filename '${new_filename}' already exists" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mv "${filename}" "${new_filename}"
|
||||||
|
}
|
||||||
|
|
||||||
|
for filename in "${@}"; do
|
||||||
|
if ends_with_bak "${filename}"; then
|
||||||
|
_unbak "${filename}"
|
||||||
|
else
|
||||||
|
_bak "${filename}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
26
home/user/.local/bin/cleanup-directory
Executable file
26
home/user/.local/bin/cleanup-directory
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
|
||||||
|
directory="$(realpath "${1}")"
|
||||||
|
readonly directory
|
||||||
|
readonly age="+21" # Notation: +n => "At least n days"
|
||||||
|
|
||||||
|
if [ ! -d "${directory}" ]; then
|
||||||
|
echo "Directory '${directory}' not found" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${DRYRUN}" ]; then
|
||||||
|
echo "Deleting files not accessed for a ${age} days:"
|
||||||
|
find "${directory}" -mindepth 1 -atime "${age}" -not -type d -not -name cleanup.log
|
||||||
|
|
||||||
|
echo "Deleting empty directories:"
|
||||||
|
find "${directory}" -mindepth 1 -type d -empty
|
||||||
|
else
|
||||||
|
echo "Deleting files not accessed for a ${age} days:"
|
||||||
|
find "${directory}" -mindepth 1 -atime "${age}" -not -type d -not -name cleanup.log -print -delete
|
||||||
|
|
||||||
|
echo "Deleting empty directories:"
|
||||||
|
find "${directory}" -mindepth 1 -type d -empty -print -delete
|
||||||
|
fi
|
||||||
22
home/user/.local/bin/cleanup-directory-log
Executable file
22
home/user/.local/bin/cleanup-directory-log
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
|
||||||
|
directory="$(realpath "${1}")"
|
||||||
|
readonly directory
|
||||||
|
|
||||||
|
if [ ! -d "${directory}" ]; then
|
||||||
|
echo "Directory '${directory}' not found" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
readonly log_file="${directory}/cleanup.log"
|
||||||
|
|
||||||
|
if [ -n "${DRYRUN}" ]; then
|
||||||
|
log_file="/dev/null"
|
||||||
|
fi
|
||||||
|
|
||||||
|
touch "${log_file}"
|
||||||
|
|
||||||
|
echo "$(date -Iseconds) : Start cleanup" >> "${log_file}"
|
||||||
|
cleanup-directory "${directory}" | tee -a "${log_file}"
|
||||||
5
home/user/.local/bin/cleanup-downloads
Executable file
5
home/user/.local/bin/cleanup-downloads
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
readonly downloads_directory="${XDG_DOWNLOAD_DIR}"
|
||||||
|
cleanup-directory-log "${downloads_directory}"
|
||||||
5
home/user/.local/bin/gobuild
Executable file
5
home/user/.local/bin/gobuild
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
#shellcheck disable=SC2068
|
||||||
|
go build $@ -o ./bin/ ./...
|
||||||
8
home/user/.local/bin/json
Executable file
8
home/user/.local/bin/json
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
if [ -t 0 ]; then
|
||||||
|
echo "${@}" | python -m json.tool
|
||||||
|
else
|
||||||
|
python -m json.tool
|
||||||
|
fi
|
||||||
10
home/user/.local/bin/mcd
Executable file
10
home/user/.local/bin/mcd
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
if [ -z "${1}" ]; then
|
||||||
|
dir="$(mktemp -ut "${USER:-user}.XXXX")"
|
||||||
|
else
|
||||||
|
dir="${1}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "${dir}" && cd "${dir}"
|
||||||
9
home/user/.local/bin/open
Executable file
9
home/user/.local/bin/open
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
|
||||||
|
if [ ! -e "${1}" ]; then
|
||||||
|
printf 'File %s not found' "${1}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
setsid xdg-open "${1}" 1>/dev/null 2>&1
|
||||||
9
home/user/.local/bin/py
Executable file
9
home/user/.local/bin/py
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
|
||||||
|
if [ -z "${*}" ] && [ -x "$(command -v ipython 2>/dev/null)" ]; then
|
||||||
|
ipython -i -c "q = exit"
|
||||||
|
else
|
||||||
|
python3 "${@}"
|
||||||
|
fi
|
||||||
11
home/user/.local/bin/sha
Executable file
11
home/user/.local/bin/sha
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
|
||||||
|
if [ -n "${2+x}" ]; then
|
||||||
|
shasum -a 256 "${@}"
|
||||||
|
elif [ -n "${1+x}" ]; then
|
||||||
|
shasum -a 256 "${@}" | head -c 64
|
||||||
|
else
|
||||||
|
shasum -a 256 | head -c 64
|
||||||
|
fi
|
||||||
12
home/user/.local/bin/showtips
Executable file
12
home/user/.local/bin/showtips
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
|
||||||
|
readonly tips_dir="${HOME}/.tips"
|
||||||
|
|
||||||
|
if [ ! -d "${tips_dir}" ]; then
|
||||||
|
mkdir "${tips_dir}" 2>/dev/null
|
||||||
|
git init "${tips_dir}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
find "${tips_dir}" -mindepth 1 -maxdepth 1 -type f -exec cat {} \;
|
||||||
5
home/user/.local/bin/weather
Executable file
5
home/user/.local/bin/weather
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
readonly city="${1}"
|
||||||
|
curl "wttr.in/${city}" 2>/dev/null | head -n -1
|
||||||
Loading…
x
Reference in New Issue
Block a user