dotfiles

custom linux config files managed with gnu stow

dotfiles

zsh/.config/zsh/07-functions.zsh


#                 ██
#  ██████  ██████░██
# ░░░░██  ██░░░░ ░██████
#    ██  ░░█████ ░██░░░██
#   ██    ░░░░░██░██  ░██
#  ██████ ██████ ░██  ░██
# ░░░░░░ ░░░░░░  ░░   ░░
#
#  ▓▓▓▓▓▓▓▓▓▓
# ░▓ author ▓ xero <x@xero.style>
# ░▓ code   ▓ https://code.x-e.ro/dotfiles
# ░▓ mirror ▓ https://git.io/.files
# ░▓▓▓▓▓▓▓▓▓▓
# ░░░░░░░░░░
#
#█▓▒░ shorter octal list
function l() {
		ls -gGAhF --color=always "$@" \
		| sed -e '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;s/rwt/7/g' \
		| sed -e 's/^\(....\) [[:digit:]] / /'
}

#█▓▒░ tmux
function t() {
	X=$#
	[[ $X -eq 0 ]] || X=X
	tmux new-session -A -s "$X"
	tmux set-environment LC_ALL 'en_US.UTF-8'
	tmux set-environment LANG 'en_US.UTF-8'
}

#█▓▒░ {de,}compression
uz() {
  if [[ -f  ]]; then
    case  in
      *.tar.bz2)  tar xvjf "" ;;
      *.tar.gz)   tar xvzf "" ;;
      *.bz2)       bunzip2 "" ;;
      *.rar)       unrar x "" ;;
      *.gz)         gunzip "" ;;
      *.tar)       tar xvf "" ;;
      *.tbz2)     tar xvjf "" ;;
      *.tgz)      tar xvzf "" ;;
      *.zip)         unzip "" ;;
      *.Z)      uncompress "" ;;
      *.7z)           7z x "" ;;
      *.xz)           unxz "" ;;
			*)             echo "'' unknown compression" ;;
    esac
  else
    echo "'' not a valid file"
  fi
}
z() {
	if [[ -f "" ||  -d "" ]]; then
		tar zcvf "_$(date '+%Y-%m-%d').tar.gz" "";
	else
		echo "not a valid file or dir"
	fi
}

#█▓▒░ disk info
function disks() {
	# echo
	function _e() {
		title=$(echo "" | sed 's/./& /g')
		echo "
3[0;31m╓─────3[0;35m ${title}
3[0;31m╙────────────────────────────────────── ─ ─"
	}
	# loops
	function _l() {
		X=$(printf '3[0m')
		G=$(printf '3[0;32m')
		R=$(printf '3[0;35m')
		C=$(printf '3[0;36m')
		W=$(printf '3[0;37m')
		i=0;
		while IFS= read -r line || [[ -n $line ]]; do
			if [[ $i == 0 ]]; then
				echo "${G}${line}${X}"
			else
				if [[ "$line" == *"%"* ]]; then
					percent=$(echo "$line" | awk '{ print  }' | sed 's!%!!')
					color=$W
					((percent >= 75)) && color=$C
					((percent >= 90)) && color=$R
					line=$(echo "$line" | sed "s/${percent}%/${color}${percent}%${W}/")
				fi
				echo "${W}${line}${X}" | sed "s/\([─└├┌┐└┘├┤┬┴┼]\)/${R}${W}/g; s! \(/.*\)! ${C}${W}!g;"
			fi
			i=$((i+1))
		done < <(printf '%s' "")
	}
	# outputs
	m=$(lsblk -a | grep -v loop)
	_e "mount.points"
	_l "$m"
	d=$(df -h)
	_e "disk.usage"
	_l "$d"
	s=$(swapon --show)
	_e "swaps"
	_l "$s"
}

#█▓▒░ 1password
function 1pwaccount() {
	domain="${3:-my}.1password.com"
	op account add \
		--address "$domain" \
		--email "" \
		--shorthand ""
}
function 1pwsignin() {
	# muliuser fun times
	echo "unlock your keychain 🔐"
	read -rs _pw
	if [[ -n "$_pw" ]]; then
		printf "logging in: "
		accounts=("${(f)$(op account list | tail -n +2 | cut -d' ' -f1)}")
		for acct in "${accounts[@]}" ;do
			printf "%s " "$acct"
			eval $(echo "$_pw" | op signin --account "$acct")
		done
		echo
	fi
}
function 1pwcheck() {
	[[ -z "$(op vault user list private --account  2>/dev/null)" ]] && 1pwsignin || return true
}
function 1pw() {
	f="${3:-notesPlain}"
	[[ "" =~ "^http" ]] && i=$(1pwurl "") || i=""
	1pwcheck "" && op item get "$i" --account "" --fields "$f" --format json | jq -rM '.value'
}
function 1pwedit() {
	[[ -z "" ]] && { read val; } || { val=; }
	1pwcheck "" && op item edit --account "" "" "=${val}"
}
function 1pwfile() {
	f="${4:-notesPlain}"
	1pwcheck "" && op --account "" read "op:////$f"
}
function 1pweditfile() {
	1pwcheck "" && op item edit --account "" "" "files.[file]="
}
function 1pwurl() {
	echo "" | sed 's/^.*i=//;s/\&.*$//'
}

#█▓▒░ revive your drive
function docclean() {
	sudo docker rm $(sudo docker ps -a -q)
	sudo docker rmi $(sudo docker images -q)
}

#█▓▒░ ascii
alias ascii="toilet -t -f 3d"
alias future="toilet -t -f future"
alias rusto="toilet -t -f rusto"
alias rustofat="toilet -t -f rustofat"
function toiletlist() {
	TXT=
	[ -z "$TXT" ] && TXT="{}"
	ls ${TOILET_FONT_PATH:=/usr/share/figlet} | sed 's/\.[^.]*$//' | fzf --preview="toilet -f {} ${TXT}" --preview-window=right:80%:noborder --color preview-bg:#1c1c1c
}

#█▓▒░ ansi
function tdlist() {
	TXT=
	[ -z "$TXT" ] && TXT="{}"
	ls /home/x0/.config/tdfgo/fonts | sed 's/\.[^.]*$//' | fzf --preview="tdfgo print -f {} ${TXT}" --preview-window=right:80%:noborder --color preview-bg:#1c1c1c
}

#█▓▒░ read stuff like manpages
function md() {
	pandoc -s -f markdown -t man "$*" | man -l -
}
function manwww() {
	curl -skL "$*" | pandoc -s -f html -t man | man -l -
}

#█▓▒░ hack time
function gitforge() {
	[[ ! -d .git ]] && echo "not a git repo" && return
	gitauthor=`git config user.name`
	printf "author ($gitauthor): "
	read -r author
	author=${author:=$gitauthor}
	gitemail=`git config user.email`
	printf "email ($gitemail):"
	read -r email
	email=${email:=$gitemail}
	now=`date -Is`
	printf "date ($now):"
	read -r date
	date=${date:=$now}
	echo "\nhacking time as: $author <$email> $date\n"
	export GIT_AUTHOR_DATE=$date
	export GIT_AUTHOR_EMAIL=$email
	export GIT_AUTHOR_NAME=$author
	export GIT_COMMITTER_DATE=$date
	export GIT_COMMITTER_EMAIL=$email
	export GIT_COMMITTER_NAME=$author
	[[ ! "" ]] && git commit || git commit -S
	unset GIT_AUTHOR_DATE
	unset GIT_AUTHOR_EMAIL
	unset GIT_AUTHOR_NAME
	unset GIT_COMMITTER_DATE
	unset GIT_COMMITTER_EMAIL
	unset GIT_COMMITTER_NAME
}

#█▓▒░ osint
function greynoise() {
	IP="${1:-/dev/stdin}"
	[[ "$IP" =~ "stdin" ]] && read IP < "$IP"
	[[ "$IP" =~ "([0-9]{1,3}[\.]){3}[0-9]{1,3}" ]] || IP=`dig +short ${IP}`
	curl -sX GET "https://api.greynoise.io/v3/community/${IP}" -H "Accept: application/json" -H "key: ${GREY_TOKEN}"
}

Download

raw zip tar