2023-06-02 07:28:47 +00:00
|
|
|
|
(define-module (cobra homedir)
|
|
|
|
|
#:use-module (guix gexp)
|
2023-06-05 04:12:42 +00:00
|
|
|
|
#:export (%home:devspec
|
|
|
|
|
%home:bashrc
|
|
|
|
|
%home:prompt
|
|
|
|
|
%home:bash-profile))
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-05 04:12:42 +00:00
|
|
|
|
(define %home:devspec
|
2023-06-02 07:28:47 +00:00
|
|
|
|
(plain-file "devspec" "\
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
if [[ $HOSTNAME == pp ]]; then
|
2023-06-04 04:06:31 +00:00
|
|
|
|
PRIV=doas
|
|
|
|
|
UPDATE=\"$PRIV sh -c 'apk update && apk upgrade -aiv && apk fix'\"
|
|
|
|
|
COPY_COMMAND=\"wl-copy\"
|
|
|
|
|
PASTE_COMMAND=\"wl-paste\"
|
|
|
|
|
WIFI=wlan0
|
|
|
|
|
WM=\"bash\"
|
2023-06-04 23:35:03 +00:00
|
|
|
|
elif [[ $HOSTNAME == Oganesson ]]; then :
|
2023-06-04 04:06:31 +00:00
|
|
|
|
#export WLR_DRM_DEVICES=/dev/dri/card1:/dev/dri/card0
|
2023-06-02 07:28:47 +00:00
|
|
|
|
elif [[ $HOSTNAME == Neon ]]; then
|
2023-06-04 04:06:31 +00:00
|
|
|
|
export WLR_NO_HARDWARE_CURSORS=1
|
2023-06-02 07:28:47 +00:00
|
|
|
|
else
|
2023-06-04 04:06:31 +00:00
|
|
|
|
PRIV=sudo
|
|
|
|
|
UPDATE=\"$PRIV sh -c 'apt update && apt upgrade && apt autoremove'\"
|
|
|
|
|
COPY_COMMAND=\"xclip -i -selection clipboard\"
|
|
|
|
|
PASTE_COMMAND=\"xclip -o -selection clipboard\"
|
|
|
|
|
WIFI=wlp2s0
|
|
|
|
|
WM=\"bash\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
fi"))
|
|
|
|
|
|
2023-06-05 04:12:42 +00:00
|
|
|
|
(define %home:bash-profile
|
2023-06-02 07:28:47 +00:00
|
|
|
|
(plain-file "bash_profile" "\
|
|
|
|
|
# Honor per-interactive-shell startup file
|
|
|
|
|
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
|
|
|
|
|
export PATH=\"~/.local/bin:$PATH\"
|
|
|
|
|
export LESS_TERMCAP_mb='[01;32m'
|
|
|
|
|
export LESS_TERMCAP_md='[01;32m'
|
|
|
|
|
export LESS_TERMCAP_me='[0m'
|
|
|
|
|
export LESS_TERMCAP_se='[0m'
|
|
|
|
|
export LESS_TERMCAP_so='[01;47;34m'
|
|
|
|
|
export LESS_TERMCAP_ue='[0m'
|
|
|
|
|
export LESS_TERMCAP_us='[01;36m'
|
|
|
|
|
export LESS=-R
|
|
|
|
|
export PATH=~/.guix-home/profile/bin:$PATH
|
|
|
|
|
|
|
|
|
|
PATH=\"/home/cobra/perl5/bin${PATH:+:${PATH}}\"; export PATH;
|
|
|
|
|
PERL5LIB=\"/home/cobra/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}\"; export PERL5LIB;
|
|
|
|
|
PERL_LOCAL_LIB_ROOT=\"/home/cobra/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}\"; export PERL_LOCAL_LIB_ROOT;
|
|
|
|
|
PERL_MB_OPT=\"--install_base \\\"/home/cobra/perl5\\\"\"; export PERL_MB_OPT;
|
|
|
|
|
PERL_MM_OPT=\"INSTALL_BASE=/home/cobra/perl5\"; export PERL_MM_OPT;
|
|
|
|
|
|
|
|
|
|
. ~/.devspec
|
2023-06-04 23:47:19 +00:00
|
|
|
|
. ~/.guix-home/setup-environment
|
2023-06-02 07:28:47 +00:00
|
|
|
|
if [[ $(tty) == /dev/tty2 ]]; then
|
2023-06-04 04:06:31 +00:00
|
|
|
|
exec $WM
|
2023-06-02 07:28:47 +00:00
|
|
|
|
fi"))
|
|
|
|
|
|
2023-06-05 04:12:42 +00:00
|
|
|
|
(define %home:prompt
|
2023-06-02 07:28:47 +00:00
|
|
|
|
(plain-file "prompt" "\
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
# shebang for syntax highlighting purposes
|
|
|
|
|
|
|
|
|
|
# Colors
|
|
|
|
|
_NON=\"\\[\\033[0m\\]\"
|
|
|
|
|
_BLD=\"\\[\\033[1m\\]\"
|
|
|
|
|
_BLK=\"\\[\\033[30m\\]\"
|
|
|
|
|
_RED=\"\\[\\033[31m\\]\"
|
|
|
|
|
_GRN=\"\\[\\033[32m\\]\"
|
|
|
|
|
_YLW=\"\\[\\033[33m\\]\"
|
|
|
|
|
_BLU=\"\\[\\033[34m\\]\"
|
|
|
|
|
_PRP=\"\\[\\033[35m\\]\"
|
|
|
|
|
_CYN=\"\\[\\033[36m\\]\"
|
|
|
|
|
_WHT=\"\\[\\033[37m\\]\"
|
|
|
|
|
|
|
|
|
|
__debug_trap() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Set necessary pre-command variables (PROMPT_COMMAND is a
|
|
|
|
|
# command so its excluded here)
|
|
|
|
|
if [[ \"$BASH_COMMAND\" != \"$PROMPT_COMMAND\"
|
|
|
|
|
&& \"$LAST_BASH_COMMAND\" == \"$PROMPT_COMMAND\" ]]; then
|
|
|
|
|
INC_TIME=1
|
|
|
|
|
LAST_RT=\"$EPOCHREALTIME\" # This should be the last thing done in this function
|
|
|
|
|
fi
|
|
|
|
|
LAST_BASH_COMMAND=\"$BASH_COMMAND\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
trap '__debug_trap' DEBUG
|
|
|
|
|
|
|
|
|
|
__get_cmd_time() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Set hours minutes seconds and remove preceding zeros
|
|
|
|
|
local YEAR
|
|
|
|
|
local DAYS
|
|
|
|
|
local HOUR
|
|
|
|
|
local MINS
|
|
|
|
|
local SECS
|
|
|
|
|
((YEAR=10#$(($(TZ=UTC printf '%(%Y)T' \"$CMD_TIME\")))-1970))
|
|
|
|
|
((DAYS=10#$(TZ=UTC printf '%(%j)T' \"$CMD_TIME\")))
|
|
|
|
|
((HOUR=10#$(TZ=UTC printf '%(%H)T' \"$CMD_TIME\")))
|
|
|
|
|
((MINS=10#$(TZ=UTC printf '%(%M)T' \"$CMD_TIME\")))
|
|
|
|
|
((SECS=10#$(TZ=UTC printf '%(%S)T' \"$CMD_TIME\")))
|
|
|
|
|
|
|
|
|
|
# Choose whether or not to print hours minutes and seconds
|
|
|
|
|
[[ $CMD_TIME -ge 31536000 ]] && printf '%sy ' \"${YEAR}\"
|
|
|
|
|
[[ $CMD_TIME -ge 86400 ]] && printf '%sd ' \"${DAYS}\"
|
|
|
|
|
[[ $CMD_TIME -ge 3600 ]] && printf '%sh ' \"${HOUR}\"
|
|
|
|
|
[[ $CMD_TIME -ge 60 ]] && printf '%sm ' \"${MINS}\"
|
|
|
|
|
[[ $CMD_TIME -ge 1 ]] && printf '%ss ' \"${SECS}\"
|
|
|
|
|
# If you want to have a limit uncomment the next line and replace somenum with
|
|
|
|
|
# the minimum microseconds
|
|
|
|
|
# [[ $CMD_US -ge somenum ]] &&
|
|
|
|
|
printf '%sμs' \"${CMD_US:-0}\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__sig() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Giant switch case for getting the name of the signal (`kill -l`)
|
|
|
|
|
local ITR=0
|
|
|
|
|
local RET
|
|
|
|
|
for RET in \"$@\"; do
|
|
|
|
|
if [[ $ITR != 0 ]]; then
|
|
|
|
|
printf '%s|%s' \"$_WHT\" \"$_RED\"
|
|
|
|
|
fi
|
|
|
|
|
((ITR++))
|
|
|
|
|
case $RET in
|
|
|
|
|
126): \"ACCES\" ;;
|
|
|
|
|
127): \"NOENT\" ;;
|
|
|
|
|
129): \"HUP\" ;;
|
|
|
|
|
130): \"INT\" ;;
|
|
|
|
|
131): \"QUIT\" ;;
|
|
|
|
|
132): \"ILL\" ;;
|
|
|
|
|
133): \"TRAP\" ;;
|
|
|
|
|
134): \"ABRT\" ;;
|
|
|
|
|
135): \"BUS\" ;;
|
|
|
|
|
136): \"FPE\" ;;
|
|
|
|
|
137): \"KILL\" ;;
|
|
|
|
|
138): \"USR\"1 ;;
|
|
|
|
|
139): \"SEGV\" ;;
|
|
|
|
|
140): \"USR\"2 ;;
|
|
|
|
|
141): \"PIPE\" ;;
|
|
|
|
|
142): \"ALRM\" ;;
|
|
|
|
|
143): \"TERM\" ;;
|
|
|
|
|
144): \"STKFLT\" ;;
|
|
|
|
|
145): \"CHLD\" ;;
|
|
|
|
|
146): \"CONT\" ;;
|
|
|
|
|
147): \"STOP\" ;;
|
|
|
|
|
148): \"TSTP\" ;;
|
|
|
|
|
149): \"TTIN\" ;;
|
|
|
|
|
150): \"TTOU\" ;;
|
|
|
|
|
151): \"URG\" ;;
|
|
|
|
|
152): \"XCPU\" ;;
|
|
|
|
|
153): \"XFSZ\" ;;
|
|
|
|
|
154): \"VTALRM\" ;;
|
|
|
|
|
155): \"PROF\" ;;
|
|
|
|
|
156): \"WINCH\" ;;
|
|
|
|
|
157): \"IO\" ;;
|
|
|
|
|
158): \"PWR\" ;;
|
|
|
|
|
159): \"SYS\" ;;
|
|
|
|
|
16[3-9]|1[7-8][0-9]|19[0-2]): \"RT$((RET-128))\" ;; # Savagery
|
|
|
|
|
*): \"$RET\" ;; # Print exit code if not in list
|
|
|
|
|
esac
|
|
|
|
|
printf '%s' \"$_\"
|
|
|
|
|
done
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__ssh() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
local CON=($SSH_CONNECTION)
|
|
|
|
|
local SRV_IP=\"${CON[2]}\"
|
|
|
|
|
[[ -z \"$SRV_IP\" ]] && return
|
|
|
|
|
local SRV_PORT=\"${CON[3]}\"
|
|
|
|
|
# 4 chars from startand 4 chars from end
|
|
|
|
|
local SRV_IP_CUT=\"${_CYN}${SRV_IP}\"
|
|
|
|
|
[[ ${#SRV_IP} -gt 8 ]] && local SRV_IP_CUT=\"${_CYN}${SRV_IP:0:4}${_WHT}*${_CYN}${SRV_IP: -4}\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
printf '%s' \"${_GRN}${_BLU}[${SRV_IP_CUT}${_PRP}${_BLD}:${_NON}${_CYN}${SRV_PORT}${_BLU}]${_NON}\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__guix_env() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
local re='[\\(]?\\(\"([^\"]*)\"'
|
|
|
|
|
if [[ \"$GUIX_ENVIRONMENT\" ]]; then
|
|
|
|
|
local PACKAGES=($(while read -r line; do
|
|
|
|
|
[[ \"$line\" =~ $re ]] && printf '%s ' \"${BASH_REMATCH[1]}\"
|
|
|
|
|
done < $GUIX_ENVIRONMENT/manifest))
|
|
|
|
|
if [[ ${#PACKAGES[@]} -eq 2 ]]; then
|
|
|
|
|
printf \"${_BLD}${_BLU}[${_NON}${_YLW}Guix${_NON}: ${_WHT}%s ${_NON}+ ${_PRP}%d ${_NON}pkg${_BLD}${_BLU}] \" \"${PACKAGES[0]}\" \"$((${#PACKAGES[@]}-1))\"
|
|
|
|
|
elif [[ ${#PACKAGES[@]} -gt 2 ]]; then
|
|
|
|
|
printf \"${_BLD}${_BLU}[${_NON}${_YLW}Guix${_NON}: ${_WHT}%s ${_NON}+ ${_PRP}%d ${_NON}pkgs${_BLD}${_BLU}] \" \"${PACKAGES[0]}\" \"$((${#PACKAGES[@]}-1))\"
|
|
|
|
|
else
|
|
|
|
|
printf \"${_BLD}${_BLU}[${_NON}${_YLW}Guix${_NON}: ${_WHT}%s${_BLD}${_BLU}] \" \"${PACKAGES[@]}\"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__prompt() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Get exit code (must be first)
|
|
|
|
|
local PLC=(\"${PIPESTATUS[@]}\")
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Reset time when prompt was first displayed after command
|
|
|
|
|
# this contributes to the ~40 microsecond difference in $CMD_US and the actual time it took
|
|
|
|
|
if [[ \"$INC_TIME\" != 0 ]]; then
|
|
|
|
|
PROMPT_RT=\"$EPOCHREALTIME\"
|
|
|
|
|
INC_TIME=0
|
|
|
|
|
fi
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# *_RT may not be set
|
|
|
|
|
LAST_RT=\"${LAST_RT:-$EPOCHREALTIME}\"
|
|
|
|
|
PROMPT_RT=\"${PROMPT_RT:-$EPOCHREALTIME}\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Get relative times
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Remove decimal point, simulating multiplying by 1 million
|
|
|
|
|
PROMPT_RT1M=\"${PROMPT_RT/.}\"
|
|
|
|
|
PROMPT_RT1M=\"${PROMPT_RT1M/,}\"
|
|
|
|
|
LAST_RT1M=\"${LAST_RT/.}\"
|
|
|
|
|
LAST_RT1M=\"${LAST_RT1M/,}\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
((CMD_US=PROMPT_RT1M-LAST_RT1M))
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
CMD_TIME=0
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Divide by 1 million to get a more accurate difference
|
|
|
|
|
((CMD_TIME=CMD_US/1000000))
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
[[ ${#CMD_US} -lt 6 ]] || CMD_US=\"${CMD_US: -6}\"
|
|
|
|
|
((CMD_US=10#$CMD_US))
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Set prompt sections
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
local SIG
|
|
|
|
|
local COL
|
|
|
|
|
local UHD
|
|
|
|
|
local TIME
|
|
|
|
|
local IND
|
|
|
|
|
local GUIX
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Text
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# ssh detection and indicator
|
|
|
|
|
[[ \"$SSH_CONNECTION\" ]] && local SSH=\"$(__ssh) \"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# [INT], [4], etc.
|
|
|
|
|
local RET
|
|
|
|
|
for RET in \"${PLC[@]}\"; do
|
|
|
|
|
if [[ $RET -gt 0 ]]; then
|
|
|
|
|
SIG=\"$(printf '%s[%s%s%s] ' \"$_BLU\" \"$_RED\" \"$(__sig \"${PLC[@]}\")\" \"$_BLU\")\"
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
done
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Guix shell environment
|
|
|
|
|
GUIX=\"$(__guix_env)\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# [user@homeserver:~]
|
|
|
|
|
COL=\"$([[ $UID == 0 ]] && printf '%s' \"$_RED\" || printf '%s' \"$_YLW\")\"
|
|
|
|
|
UHD=\"${_BLD}${_BLU}[${COL}\\u${_PRP}@${_CYN}\\h${_PRP}:${_GRN}\\w${_BLU}]\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# 2y 351d 12m 43s 382969μs
|
|
|
|
|
TIME=\"${_YLW}$(__get_cmd_time)\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Random colored $ or #
|
|
|
|
|
_RAND256=\"\\[\\033[38;2;$((RANDOM%256));$((RANDOM%256));$((RANDOM%256))m\\]\"
|
|
|
|
|
IND=\"${_RAND256}\\\\$\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
# Set the prompt
|
|
|
|
|
PS1=\"${_NON}${SSH}${GUIX}${SIG}${UHD} ${TIME} ${IND} ${_NON}\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
2023-06-04 04:06:31 +00:00
|
|
|
|
|
2023-06-02 07:28:47 +00:00
|
|
|
|
PROMPT_COMMAND=__prompt"))
|
|
|
|
|
|
2023-06-05 04:12:42 +00:00
|
|
|
|
(define %home:bashrc
|
2023-06-02 07:28:47 +00:00
|
|
|
|
(plain-file "bashrc" "\
|
|
|
|
|
# Source other files
|
|
|
|
|
[ -r ~/.prompt ] && . ~/.prompt
|
|
|
|
|
[ -r ~/.devspec ] && . ~/.devspec
|
|
|
|
|
[ -r ~/.config/colorscheme ] && . ~/.config/colorscheme
|
|
|
|
|
|
|
|
|
|
[ \"$TERM\" == \"screen.linux\" ] && export TERM=\"screen\"
|
|
|
|
|
|
|
|
|
|
export EDITOR=\"vim\"
|
|
|
|
|
export TERM=xterm-256color
|
|
|
|
|
|
|
|
|
|
# History stuff
|
|
|
|
|
export HISTCONTROL=ignoredups:erasedups
|
|
|
|
|
export HISTFILESIZE=1000
|
|
|
|
|
export HISTSIZE=1000
|
|
|
|
|
|
|
|
|
|
export GPG_TTY=$(tty)
|
|
|
|
|
|
|
|
|
|
export MANPATH=/run/current-system/profile/share/man:/home/cobra/.guix-profile/share/man:/run/current-system/profile/share/man:/home/cobra/.guix-home/profile/share/man
|
|
|
|
|
|
|
|
|
|
clear() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
printf '\\033c' # faster than ncurses clear by a lot
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Other aliases
|
|
|
|
|
alias c='clear'
|
|
|
|
|
alias ls='ls --color=auto -FAh'
|
|
|
|
|
alias ll='ls -l'
|
|
|
|
|
alias nf='hyfetch'
|
|
|
|
|
alias ga='git add'
|
|
|
|
|
alias gc='git commit -sS'
|
|
|
|
|
alias gp='git push'
|
|
|
|
|
alias mpv='mpv --no-audio-display'
|
|
|
|
|
alias wv='swayhide mpv $($PASTE_COMMAND)'
|
|
|
|
|
alias curl='curl -L'
|
|
|
|
|
alias prof='profanity'
|
|
|
|
|
alias gomuks=\"http_proxy='socks5://127.0.0.1:9050' gomuks\"
|
|
|
|
|
alias tut=\"http_proxy='socks5://127.0.0.1:9050' tut\"
|
|
|
|
|
alias dico=\"dico -d en-wiktionary\"
|
|
|
|
|
|
|
|
|
|
# Random string (passwords)
|
|
|
|
|
randstr() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
tr -cd '[:graph:]' </dev/urandom | head -c ${1:-256}
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Get CPU usage
|
|
|
|
|
cpusage() {
|
|
|
|
|
bc<<<\"scale=3;$(ps aux | awk 'BEGIN {sum=0} {sum+=$3}; END {print sum}') / $(nproc --all)\"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Update and upgrade system
|
2023-06-04 18:45:39 +00:00
|
|
|
|
update() { eval \"$UPDATE\"; }
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
|
|
|
|
# Im too lazy to type
|
|
|
|
|
copy() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
printf \"%s\" \"$(</dev/stdin)\" > >($COPY_COMMAND)
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# URL-encode stdin
|
|
|
|
|
urlencode() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
LC_COLLATE_OLD=$LC_COLLATE
|
|
|
|
|
LC_COLLATE=C
|
2023-06-02 07:28:47 +00:00
|
|
|
|
|
2023-06-04 04:06:31 +00:00
|
|
|
|
local TEXT=\"$(</dev/stdin)\"
|
|
|
|
|
local LENGTH=\"${#TEXT}\"
|
|
|
|
|
for (( i = 0; i < LENGTH; i++ )); do
|
|
|
|
|
local c=\"${TEXT:$i:1}\"
|
|
|
|
|
case $c in
|
|
|
|
|
[a-zA-Z0-9.~_-]) printf '%s' \"$c\" ;;
|
|
|
|
|
*) printf '%%%02X' \"'$c\" ;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
LC_COLLATE=$LC_COLLATE_OLD
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
diffhome() { find . -type f -regex '\\./\\.[^g].*' -exec diff -q ~/{} {} 2> /dev/null \\;; }
|
|
|
|
|
|
|
|
|
|
fixdh() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
diffhome | while read -r _ SRC _ DEST _; do
|
|
|
|
|
cp $SRC $DEST;
|
|
|
|
|
done;
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
strlen() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
N=$(wc -c <<< \"$*\")
|
|
|
|
|
((N--))
|
|
|
|
|
printf '%u\\n' \"$N\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uppweb() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
ssh vern.cc 'cd ~/public_html; git pull'
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
caption() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
[ -z \"$3\" ] && {
|
|
|
|
|
echo \"Usage: caption [input] [output] [text...]\"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
local FILE=\"$1\"
|
|
|
|
|
local OUT=\"$2\"
|
|
|
|
|
shift 2
|
|
|
|
|
local TEXT=\"$*\"
|
|
|
|
|
local WIDTH=\"$(identify -format \"%[w]\\n\" \"$FILE\" | head -n1)\"
|
|
|
|
|
local HEIGHT=\"$(identify -format \"%[h]\\n\" \"$FILE\" | head -n1)\"
|
|
|
|
|
local FONT_SIZE=\"$(((HEIGHT+WIDTH)/20))\"
|
|
|
|
|
convert -gravity north \\( -size \"${WIDTH}x\" -pointsize \"$FONT_SIZE\" -font 'Liberation-Sans-Bold' caption:\"$TEXT\" -gravity Center -extent \"${WIDTH}x\" \\) \"$FILE\" -append \"$OUT\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
captionvid() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
[ -z \"$3\" ] && {
|
|
|
|
|
echo \"Usage: captionvid [input] [output] [text...]\"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
rm /tmp/caption.*.png
|
|
|
|
|
FPS=\"$(ffmpeg -i \"$1\" 2>&1 |grep fps | sed 's/.* \\([0-9]\\+\\) fps.*/\\1/')\"
|
|
|
|
|
IN=\"$1\"
|
|
|
|
|
OUT=\"$2\"
|
|
|
|
|
shift 2
|
|
|
|
|
ffmpeg -i \"$IN\" \"/tmp/caption.%02d.png\"
|
|
|
|
|
for i in /tmp/caption.*; do
|
|
|
|
|
caption \"$i\" \"$i-new.png\" \"$*\"
|
|
|
|
|
done
|
|
|
|
|
ffmpeg -framerate $FPS -i \"/tmp/caption.%02d.png-new.png\" \"$OUT\"
|
|
|
|
|
rm /tmp/caption.*.png
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topbottom() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
[ -z \"$3\" ] && {
|
|
|
|
|
echo \"Usage: caption [input] [output] [text...]\"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
local FILE=\"$1\"
|
|
|
|
|
local OUT=\"$2\"
|
|
|
|
|
shift 2
|
|
|
|
|
local WIDTH=\"$(identify -format \"%[w]\\n\" \"$FILE\" | head -n1)\"
|
|
|
|
|
local HEIGHT=\"$(identify -format \"%[h]\\n\" \"$FILE\" | head -n1)\"
|
|
|
|
|
local FONT_SIZE=\"$(((HEIGHT+WIDTH)/20))\"
|
|
|
|
|
convert -size \"${WIDTH}x\" -stroke black -strokewidth 3 -fill white -pointsize \"$FONT_SIZE\" -font 'Liberation-Sans-Bold' -gravity Center -extent \"${WIDTH}x\" -gravity north \\( -annotate +0+0 \"$1\" \\) -gravity south \\( -annotate +0+0 \"$2\" \\) \"$FILE\" -append \"$OUT\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
topbottomvid() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
[ -z \"$3\" ] && {
|
|
|
|
|
echo \"Usage: captionvid [input] [output] [text...]\"
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
rm /tmp/caption.*.png
|
|
|
|
|
FPS=\"$(ffmpeg -i \"$1\" 2>&1 |grep fps | sed 's/.* \\([0-9]\\+\\) fps.*/\\1/')\"
|
|
|
|
|
IN=\"$1\"
|
|
|
|
|
OUT=\"$2\"
|
|
|
|
|
shift 2
|
|
|
|
|
ffmpeg -i \"$IN\" \"/tmp/caption.%02d.png\"
|
|
|
|
|
for i in /tmp/caption.*; do
|
|
|
|
|
topbottom \"$i\" \"$i-new.png\" \"$1\" \"$2\"
|
|
|
|
|
done
|
|
|
|
|
ffmpeg -framerate $FPS -i \"/tmp/caption.%02d.png-new.png\" \"$OUT\"
|
|
|
|
|
rm /tmp/caption.*.png
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
subcipher() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
local COLOR PERM L1 line grep word
|
|
|
|
|
if [ $# -lt 3 ]; then
|
|
|
|
|
if [ $# -lt 2 ] || [[ \"$1\" != \"0\" && \"$1\" != \"1\" ]]; then
|
|
|
|
|
printf \"Usage: [0|1] subcipher file [string...]\\n\"
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
COLOR=\"$1\"
|
|
|
|
|
shift
|
|
|
|
|
PERM=\"$1\"
|
|
|
|
|
shift
|
|
|
|
|
[ -z \"$*\" ] && set -- \"$(</dev/stdin)\"
|
|
|
|
|
L1=\"$(head -1 \"$PERM\")\"
|
|
|
|
|
while read -r line; do
|
|
|
|
|
tr \"${L1^^}${L1}\" \"${line^^}${line}\" <<< \"$*\"
|
|
|
|
|
done < \"$PERM\" | \
|
|
|
|
|
while read -r line; do
|
|
|
|
|
for word in $line; do
|
|
|
|
|
[ $COLOR -eq 1 ] && grep=\"$(grep --color=always -xF \"$word\" /etc/dictionaries-common/words)\"
|
|
|
|
|
printf %s \"${grep:-$word} \"
|
|
|
|
|
done
|
|
|
|
|
printf '\\n'
|
|
|
|
|
done
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playcd() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
mpv --start=00:00:00.0000000 av://libcdio:/dev/cdrom --cache=yes
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playdvd() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
mpv --start=00:00:00.0000000 dvd:///dev/sr0 --cache=yes
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gpginfo() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
gpg --with-colons --import-options show-only --import
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lc() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
fc -nl $HISTCMD | sed 's/^\\s*//'
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
baseto() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
if [ $# -ge 3 ]; then
|
|
|
|
|
local i=\"$1\"
|
|
|
|
|
local o=\"$2\"
|
|
|
|
|
shift 2
|
|
|
|
|
bc <<< \"obase=$o;$(($i#$*))\"
|
|
|
|
|
else
|
|
|
|
|
local line i o n
|
|
|
|
|
while read -r line; do
|
|
|
|
|
read -r i o n <<< \"$line\"
|
|
|
|
|
bc <<< \"obase=$o;$(($i#$n))\"
|
|
|
|
|
done
|
|
|
|
|
fi
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rebash() { . ~/.bashrc; }
|
|
|
|
|
bashrc() { \"$EDITOR\" ~/.bashrc && rebash; }
|
|
|
|
|
|
|
|
|
|
uplot() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
ssh vern \"${1:-/opt/gnuplot/users/gnuplot.sh}; cat /opt/gnuplot/users/${1:-$(date -u -I)}.svg\" > ${1:-$(date -u -I)}.svg
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mnplot() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
ssh mythos \"${1:-/opt/gnuplot/gnuplot.sh}; cat /opt/gnuplot/${1:-$(date -u -I)}.svg\" > ${1:-$(date -u -I)}.svg
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vnplot() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
ssh vern \"${1:-/opt/gnuplot/net/gnuplot.sh}; cat /opt/gnuplot/net/${1:-$(date -u -I)}.svg\" > ${1:-$(date -u -I)}.svg
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vpplot() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
ssh vern \"${1:-/opt/gnuplot/power/gnuplot.sh}; cat /opt/gnuplot/power/${1:-$(date -u -I)}.svg\" > ${1:-$(date -u -I)}.svg
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inplot() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
ssh iceberg \"${1:-~/gnuplot/gnuplot.sh}; cat ~/gnuplot/${1:-$(date -u -I)}.svg\" > ${1:-$(date -u -I)}.svg
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cnplot() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
ssh crescent \"${1:-/opt/gnuplot/net/gnuplot.sh}; cat /opt/gnuplot/net/${1:-$(date -u -I)}.svg\" > ${1:-$(date -u -I)}.svg
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cpplot() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
ssh crescent \"${1:-/opt/gnuplot/power/gnuplot.sh}; cat /opt/gnuplot/power/${1:-$(date -u -I)}.svg\" > ${1:-$(date -u -I)}.svg
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
reconf() {
|
2023-06-04 18:45:39 +00:00
|
|
|
|
$PRIV guix system reconfigure /etc/guix-config/${HOSTNAME,,}.scm
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hreconf() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
guix home reconfigure $HOME/.config/guix/home.scm
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
geng() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
< \"$1\" sed 's/\\s*;.*//' | grep -ve '^$' -e '^T' | awk '{print \"N\"NR\" \"$0}' > \"$2\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mkmshex() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
FILE=\"${1%.*}\"
|
|
|
|
|
microscheme \"$1\"
|
|
|
|
|
avr-gcc -B /run/current-system/profile/avr/lib/avr5 -mmcu=\"$2\" -g -Os \"$FILE\".s -o \"$FILE\".elf
|
|
|
|
|
avr-objcopy -Oihex \"$FILE\".o \"$FILE\".hex
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uploadhex() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
avrdude -C/run/current-system/profile/etc/avrdude.conf -v -p\"$2\" -carduino -P${3:-/dev/ttyS0} -U\"flash:w:$1:i\"
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gshpkg() {
|
2023-06-04 04:06:31 +00:00
|
|
|
|
local re='[\\(]?\\(\"([^\"]*)\"'
|
|
|
|
|
if [[ \"$GUIX_ENVIRONMENT\" ]]; then
|
|
|
|
|
local PACKAGES=($(while read -r line; do
|
|
|
|
|
[[ \"$line\" =~ $re ]] && printf '%s ' \"${BASH_REMATCH[1]}\"
|
|
|
|
|
done < $GUIX_ENVIRONMENT/manifest))
|
|
|
|
|
echo ${PACKAGES[@]}
|
|
|
|
|
fi
|
2023-06-02 07:28:47 +00:00
|
|
|
|
}"))
|