logo

dotfiles

My dotfiles, one branch per machine, rebased on base
commit: 12cfd637298fe840bdca3d42c4a7f796f87b2472
parent: 0c74ed0a1cdf5882cb58c3e653cb30fe3a35d894
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sat,  4 Apr 2020 14:12:46 +0200

Re-introduce ~/.common.sh as ENV=~/.profile is a bad hack

Diffstat:

A.common.sh134+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
M.mkshrc2++
M.profile131-------------------------------------------------------------------------------
3 files changed, 136 insertions(+), 131 deletions(-)

diff --git a/.common.sh b/.common.sh @@ -0,0 +1,134 @@ +# Aliases +alias bash="SHELL=/bin/bash bash -l" +alias bc="bc ~/Sources/git/hacktivis.me/git/blog/notes/bc.txt" +alias fuck='TF_ALIAS=fuck eval $(thefuck $(fc -ln -1))' +alias fuu='su -c "$(fc -ln -1)"' +alias git-st="git status --short --branch" +alias git-story="git log --graph --abbrev-commit --decorate --format=format:'%C(cyan)%h%C(reset) %C(green)(%ad)%C(reset) %G?: %s %C(red)- %an %C(reset)%C(yellow)%d%C(reset)'" +alias j='jobs -l' +alias la='ls -ahF' +alias ll='ls -alhF' +alias ls='ls -hF' +alias mv='mv -i' +alias pscpu='ps -eo pid,user,pcpu,pmem,comm --sort -pcpu | head -20' +alias psmem='ps -eo pid,user,pcpu,pmem,comm --sort -pmem | head -20' +alias rm='rm -ri' +alias sleep="/bin/sleep" # avoid sleep as a builtin +alias xstart='startx -- $(tty | sed "s/\/dev\/tty/vt/")' +alias .='cd .' +alias ..='cd ..' +alias ...='cd ../..' + +# = functions = +# Note: POSIX only allows [0-9a-z_A-Z] in function names + +get_git_branch() { + if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then + case "$branch" in + "HEAD") + branch='detached*' + ;; + "$(hostname)") + branch='@.' + ;; + esac + + printf -- ' %s' "$branch" + else + echo '' + fi + + unset branch +} + +get_working_directory() { + pwd | sed "s|^$HOME|~|" +} + +# == prompt setup == +case $(hostname) in + NightmareMoon) host_ansi="33" ;; + hp2125) host_ansi="37" ;; + *) host_ansi="31" ;; +esac + +case $SHELL in + *ksh*) + # hack derived from ksh88(1), works in mksh, doesn't works in bash + export PS1=' $?$(date +w%wT%T)${USER}[${host_ansi}m@$(hostname)$(get_working_directory)$(get_git_branch) ' + ;; + *bash*) + export PS1='\[\e[47;30m\]$?\[\e[37;100m\]\[\e[100;30m\]$(date +w%wT%T)\[\e[40;90m\]\[\e[40;32m\]\u\[\e[${host_ansi}m\]@\h\]\[\e[30;46m\]$(get_working_directory)\[\e[0;36m\]\[\e[0m\] ' + ;; + *) + # Don't even try escape codes, and so no powerline-style + export PS1='$? $(date +w%wT%T) $USER@${HOSTNAME:=$(hostname)} $(get_working_directory) $(get_git_branch) > ' + ;; +esac + +# = helpers = +ssh_add_all() { + ssh-add $(find ~/.ssh -name 'id_*' -a \( \! -name '*.pub' \)) +} + +ssh_start_agent() { + code="$(ssh-add -l; echo $?)" + + case "${code}" in + 0) echo 'Managed to list keys, SSH agent appear to be active' ;; + 1) echo 'Failed to list keys' ;; + 2) + rm -fr "$SSH_AUTH_SOCK" + eval $(ssh-agent -a $SSH_AUTH_SOCK) + echo "$SSH_AGENT_PID" > ~/.ssh/agent.pid + return 0 + ;; + *) echo 'Unknown return code: '${code} ;; + esac + + return 1 +} + +ssh_tunnel() { + local port=${1:-443} + local server=${2:-hacktivis.me} + local target_port=${3:-22$port} + local target_host=${4:-localhost} + + echo "ssh -NL $target_port:$target_host:$port $server" + ssh -NL $target_port:$target_host:$port $server +} + +xdg_desktop_menu() { + echo $1 $2 $3 + if [$1 = 'install']; then + cp $2 ${XDG_DESKTOP_DIR:-~/Desktop} + fi +} + +ssh_socks() { + local server=${1:-hacktivis.me} + local port=${2:-22443} + + echo "ssh -ND $port $server" + ssh -ND $port $server +} + +pmounts() { + awk 'BEGIN { print "Mountpoint Type Device Options" } { print $2 " " $3 " " $1 " " $4 | "sort"}' /proc/mounts | column -t -s\ +} + +grep_unicode() { + grep "$1" /usr/share/unicode-data/UnicodeData.txt | awk -F\; '{ system("unicode -t "$1); print FS "U+"$1 FS $2 }' | column -s\; -t +} +wtf_unicode() { + wat-unicode $(unicode -h "$1") +} + +wat_unicode() { + awk -F\; '{ if($1 == "'${1}'"){print "U+"$1 FS $2} }' /usr/share/unicode-data/UnicodeData.txt +} + +# startup + +stty sane # I can haz urandom diff --git a/.mkshrc b/.mkshrc @@ -1,3 +1,5 @@ set -o notify set -o markdirs set -o braceexpand + +. ~/.common.sh diff --git a/.profile b/.profile @@ -3,7 +3,6 @@ export ACRONYMDB="$HOME/.local/share/acronyms" export BADWOLF_L10N="en_GB:fr_FR:de_DE:ru_RU" export BROWSER="badwolf:firefox:lynx" export EDITOR="$(which vis)" -export ENV="$HOME/.profile" export GOPROXY="direct" # disable proxying to Google by default export GOSUMDB=off # do not query for module checksum when undefined in go.sum export GO111MODULE=on @@ -85,134 +84,4 @@ export LIBVA_DRIVER_NAME=radeonsi ## Fuck off GNUisms export POSIXLY_CORRECT=1 -# Aliases -alias bash="SHELL=/bin/bash bash -l" -alias bc="bc ~/Sources/git/hacktivis.me/git/blog/notes/bc.txt" -alias fuck='TF_ALIAS=fuck eval $(thefuck $(fc -ln -1))' -alias fuu='su -c "$(fc -ln -1)"' -alias git-st="git status --short --branch" -alias git-story="git log --graph --abbrev-commit --decorate --format=format:'%C(cyan)%h%C(reset) %C(green)(%ad)%C(reset) %G?: %s %C(red)- %an %C(reset)%C(yellow)%d%C(reset)'" -alias j='jobs -l' -alias la='ls -ahF' -alias ll='ls -alhF' -alias ls='ls -hF' -alias mv='mv -i' -alias pscpu='ps -eo pid,user,pcpu,pmem,comm --sort -pcpu | head -20' -alias psmem='ps -eo pid,user,pcpu,pmem,comm --sort -pmem | head -20' -alias rm='rm -ri' -alias sleep="$(which sleep)" # avoid sleep as a builtin -alias xstart='startx -- $(tty | sed "s/\/dev\/tty/vt/")' -alias .='cd .' -alias ..='cd ..' -alias ...='cd ../..' - -# functions -get_git_branch() { - local branch - if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null); then - if [[ "$branch" == "HEAD" ]]; then - branch='detached*' - elif [[ "$branch" == $(hostname) ]]; then - branch='@.' - fi - - printf -- ' %s' "$branch" - else - echo '' - fi -} - -get_working_directory() { - pwd | sed "s|^$HOME|~|" -} - -# = functions = -# == prompt setup == -case $(hostname) in - NightmareMoon) host_ansi="33" ;; - hp2125) host_ansi="37" ;; - *) host_ansi="31" ;; -esac - -case $SHELL in - *ksh*) - # hack derived from ksh88(1), works in mksh, doesn't works in bash - export PS1=' $?$(date +w%wT%T)${USER}[${host_ansi}m@$(hostname)$(get_working_directory)$(get_git_branch) ' - ;; - *bash*) - export PS1='\[\e[47;30m\]$?\[\e[37;100m\]\[\e[100;30m\]$(date +w%wT%T)\[\e[40;90m\]\[\e[40;32m\]\u\[\e[${host_ansi}m\]@\h\]\[\e[30;46m\]$(get_working_directory)\[\e[0;36m\]\[\e[0m\] ' - ;; - *) - # Don't even try escape codes, and so no powerline-style - export PS1='$? $(date +w%wT%T) $USER@${HOSTNAME:=$(hostname)} $(get_working_directory) $(get_git_branch) > ' - ;; -esac - -# = helpers = -ssh-add-all() { - ssh-add $(find ~/.ssh -name 'id_*' -a \( \! -name '*.pub' \)) -} - -ssh-start-agent() { - code="$(ssh-add -l; echo ${?})" - - case "${code}" in - 0) echo 'Managed to list keys, SSH agent appear to be active' ;; - 1) echo 'Failed to list keys' ;; - 2) - rm -fr "$SSH_AUTH_SOCK" - eval $(ssh-agent -a $SSH_AUTH_SOCK) - echo "$SSH_AGENT_PID" > ~/.ssh/agent.pid - return 0 - ;; - *) echo 'Unknown return code: '${code} ;; - esac - - return 1 -} - -ssh-tunnel() { - local port=${1:-443} - local server=${2:-hacktivis.me} - local target_port=${3:-22$port} - local target_host=${4:-localhost} - - echo "ssh -NL $target_port:$target_host:$port $server" - ssh -NL $target_port:$target_host:$port $server -} - -xdg-desktop-menu() { - echo $1 $2 $3 - if [$1 = 'install']; then - cp $2 ${XDG_DESKTOP_DIR:~/Desktop} - fi -} - -ssh-socks() { - local server=${1:-hacktivis.me} - local port=${2:-22443} - - echo "ssh -ND $port $server" - ssh -ND $port $server -} - -pmounts() { - awk 'BEGIN { print "Mountpoint Type Device Options" } { print $2 " " $3 " " $1 " " $4 | "sort"}' /proc/mounts | column -t -s\ -} - -grep-unicode() { - grep "$1" /usr/share/unicode-data/UnicodeData.txt | awk -F\; '{ system("unicode -t "$1); print FS "U+"$1 FS $2 }' | column -s\; -t -} -wtf-unicode() { - wat-unicode $(unicode -h "$1") -} - -wat-unicode() { - awk -F\; '{ if($1 == "'${1}'"){print "U+"$1 FS $2} }' /usr/share/unicode-data/UnicodeData.txt -} - -# startup - gpg-connect-agent /bye # Make sure gpg-agent is started - -stty sane # I can haz urandom