Compare commits
No commits in common. "f77a77b034736abf75b39689e850ec6e16f452a7" and "3924fba938a58a5aafdcab04fd0d129f08181201" have entirely different histories.
f77a77b034
...
3924fba938
218
.bash_xinitrc
218
.bash_xinitrc
|
@ -1,6 +1,9 @@
|
||||||
#! /bin/bash --
|
#! /bin/bash --
|
||||||
# ex: set ts=4 sw=4 ft=sh
|
# ex: set ts=4 sw=4 ft=sh
|
||||||
|
|
||||||
|
# Keymap
|
||||||
|
setxkbmap -layout us
|
||||||
|
|
||||||
# Enable Touchpad While Typing
|
# Enable Touchpad While Typing
|
||||||
# xinput |
|
# xinput |
|
||||||
# grep Touchpad |
|
# grep Touchpad |
|
||||||
|
@ -13,13 +16,214 @@
|
||||||
# xargs -I pid xinput set-prop "$iid" pid 0;
|
# xargs -I pid xinput set-prop "$iid" pid 0;
|
||||||
# }
|
# }
|
||||||
|
|
||||||
setxkbmap -layout us
|
pathvarprepend () {
|
||||||
three-mon
|
# prepending paths to pathvar denoted by the expansion of the PATHVAR parameter
|
||||||
updatebar
|
# if it's already in the PATH, move it to the end
|
||||||
2>/dev/null 1>&2 nohup picom &
|
# POSIX compliant version
|
||||||
2>/dev/null 1>&2 startlxde &
|
|
||||||
|
|
||||||
while : ; do
|
test -n "$2" ||
|
||||||
2>>/home/tosuman/.xinit.log 1>&2 dwm
|
{ echo "Usage: pathvarprepend PATHVAR PATH_TO_ADD [PATH_TO_ADD...]";
|
||||||
|
echo "Example: pathvarprepend LD_LIBRARY_PATH '$HOME/.local/lib' '/usr/local/lib'";
|
||||||
|
return 2; }
|
||||||
|
|
||||||
|
pathvar=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
case $pathvar in (*[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*|""|[0123456789]*) false;; esac ||
|
||||||
|
{ echo 'Expanded pathvar is not a valid name/variable identifier'; return 3; }
|
||||||
|
|
||||||
|
if [ "$pathvar" = "PATH" ]; then
|
||||||
|
test "${-#*r}" = $- ||
|
||||||
|
{ echo 'Restricted shell, cannot change PATH'; return 4; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
path_prepend_error=0
|
||||||
|
|
||||||
|
# Thanks Stephane
|
||||||
|
code="set -- dummy"
|
||||||
|
n=$#
|
||||||
|
while [ "$n" -gt 0 ]; do
|
||||||
|
code="$code \"\${$n}\""
|
||||||
|
n=$((n - 1))
|
||||||
|
done
|
||||||
|
eval "$code"
|
||||||
|
|
||||||
|
while shift; [ $# -gt 0 ]; do
|
||||||
|
norm_path_to_add=$1
|
||||||
|
|
||||||
|
test "${norm_path_to_add#*:}" = "$norm_path_to_add" ||
|
||||||
|
{ echo 'Cannot add path with colon'; path_prepend_error=1; continue; }
|
||||||
|
|
||||||
|
test -d "$norm_path_to_add" ||
|
||||||
|
{ echo "path_to_add ('$norm_path_to_add') not a directory"; path_prepend_error=1; continue; }
|
||||||
|
|
||||||
|
norm_path=$(printf %s ":$(eval "printf %s "'"'"\$$pathvar"'"'):" | head -n 1 | sed 's|/\+|/|g; s/\/$//; s/:/::/g') # fence with colons, ensure one line, deduplicate slashes, trim trailing, duplicate colons
|
||||||
|
norm_path_to_add=$(printf %s "$norm_path_to_add" | head -n 1 | sed 's|/\+|/|g; s/\/$//') # ensure one line, deduplicate slashes, trim trailing
|
||||||
|
exec 3<<- 'EOF'
|
||||||
|
# escape BRE meta-characters
|
||||||
|
s/\\/\\./g # backslash first
|
||||||
|
s/\./\\./g
|
||||||
|
s/\^/\\^/g
|
||||||
|
s/\$/\\$/g
|
||||||
|
s/\*/\\*/g
|
||||||
|
s/\[/\\[/g
|
||||||
|
s|/|\\/|g # escape delimiter for outer sed
|
||||||
|
EOF
|
||||||
|
norm_path=$(printf %s "$norm_path" | sed "s/:$(printf %s "$norm_path_to_add" | sed -f /proc/self/fd/3 3<&3)://g") # remove all instances of PATH_TO_ADD from PATH
|
||||||
|
exec 3<&-
|
||||||
|
norm_path=$(printf %s "$norm_path" | sed 's/:\+/:/g; s/^://; s/:$//') # deduplicate colons, trim leading and trailing
|
||||||
|
eval "$pathvar=\$norm_path_to_add\${norm_path:+:\$norm_path}" # prepend with colon
|
||||||
|
done
|
||||||
|
return $path_prepend_error
|
||||||
|
}
|
||||||
|
|
||||||
|
pathvarappend () {
|
||||||
|
# appending paths to pathvar denoted by the expansion of the PATHVAR parameter
|
||||||
|
# if it's already in the PATH, move it to the end
|
||||||
|
# POSIX compliant version
|
||||||
|
|
||||||
|
test -n "$2" ||
|
||||||
|
{ echo "Usage: pathappend PATHVAR PATH_TO_ADD [PATH_TO_ADD...]";
|
||||||
|
echo "Example: pathappend LD_LIBRARY_PATH '$HOME/.local/lib' '/usr/local/lib'";
|
||||||
|
return 2; }
|
||||||
|
|
||||||
|
pathvar=$1
|
||||||
|
|
||||||
|
case $pathvar in (*[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*|""|[0123456789]*) false;; esac ||
|
||||||
|
{ echo 'Expanded pathvar is not a valid name/variable identifier'; return 3; }
|
||||||
|
|
||||||
|
if [ "$pathvar" = "PATH" ]; then
|
||||||
|
test "${-#*r}" = $- ||
|
||||||
|
{ echo 'Restricted shell, cannot change PATH'; return 4; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
path_append_error=0
|
||||||
|
|
||||||
|
while shift; [ $# -gt 0 ]; do
|
||||||
|
norm_path_to_add=$1
|
||||||
|
|
||||||
|
test "${norm_path_to_add#*:}" = "$norm_path_to_add" ||
|
||||||
|
{ echo 'Cannot add path with colon'; path_append_error=1; continue; }
|
||||||
|
|
||||||
|
test -d "$norm_path_to_add" ||
|
||||||
|
{ echo "path_to_add ('$norm_path_to_add') not a directory"; path_append_error=1; continue; }
|
||||||
|
|
||||||
|
norm_path=$(printf %s ":$(eval "printf %s "'"'"\$$pathvar"'"'):" | head -n 1 | sed 's|/\+|/|g; s/\/$//; s/:/::/g') # fence with colons, ensure one line, deduplicate slashes, trim trailing, duplicate colons
|
||||||
|
norm_path_to_add=$(printf %s "$norm_path_to_add" | head -n 1 | sed 's|/\+|/|g; s/\/$//') # ensure one line, deduplicate slashes, trim trailing
|
||||||
|
exec 3<<- 'EOF'
|
||||||
|
# escape BRE meta-characters
|
||||||
|
s/\\/\\./g # backslash first
|
||||||
|
s/\./\\./g
|
||||||
|
s/\^/\\^/g
|
||||||
|
s/\$/\\$/g
|
||||||
|
s/\*/\\*/g
|
||||||
|
s/\[/\\[/g
|
||||||
|
s|/|\\/|g # escape delimiter for outer sed
|
||||||
|
EOF
|
||||||
|
norm_path=$(printf %s "$norm_path" | sed "s/:$(printf %s "$norm_path_to_add" | sed -f /proc/self/fd/3 3<&3)://g") # remove all instances of PATH_TO_ADD from PATH
|
||||||
|
exec 3<&-
|
||||||
|
norm_path=$(printf %s "$norm_path" | sed 's/:\+/:/g; s/^://; s/:$//') # deduplicate colons, trim leading and trailing
|
||||||
|
eval "$pathvar=\${norm_path:+\$norm_path:}\$norm_path_to_add" # append with colon
|
||||||
|
done
|
||||||
|
return $path_append_error
|
||||||
|
}
|
||||||
|
|
||||||
|
path_append () {
|
||||||
|
pathvarappend PATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
ld_lib_path_append () {
|
||||||
|
pathvarappend LD_LIBRARY_PATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
cdpath_append () {
|
||||||
|
pathvarappend CDPATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
path_prepend () {
|
||||||
|
pathvarprepend PATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
ld_lib_path_prepend () {
|
||||||
|
pathvarprepend LD_LIBRARY_PATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
cdpath_prepend () {
|
||||||
|
pathvarprepend CDPATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# shellcheck disable=SC2155
|
||||||
|
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
|
||||||
|
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
|
||||||
|
# export SUDO_ASKPASS="/usr/bin/sudo-askpass"
|
||||||
|
# export SSH_ASKPASS="/usr/bin/sudo-askpass"
|
||||||
|
# export SSH_ASKPASS_REQUIRE="prefer"
|
||||||
|
export GIT_CONFIG_GLOBAL="$HOME/.gitconfig"
|
||||||
|
# shellcheck disable=SC2155
|
||||||
|
export GPG_TTY="$(tty)"
|
||||||
|
export _JAVA_AWT_WM_NONREPARENTING="1"
|
||||||
|
|
||||||
|
export USER42="tischmid"
|
||||||
|
export EMAIL42="timo42@proton.me"
|
||||||
|
export MAIL="timo42@proton.me"
|
||||||
|
|
||||||
|
export GOPATH="$HOME/go"
|
||||||
|
|
||||||
|
# ld_lib_path_append \
|
||||||
|
# "${HOME}/.local/lib"
|
||||||
|
# export LD_LIBRARY_PATH
|
||||||
|
|
||||||
|
path_prepend \
|
||||||
|
"/bin" \
|
||||||
|
"/sbin" \
|
||||||
|
"/usr/bin" \
|
||||||
|
"/usr/sbin" \
|
||||||
|
"/usr/local/bin" \
|
||||||
|
"/usr/local/sbin" \
|
||||||
|
"/usr/games" \
|
||||||
|
"/usr/local/games" \
|
||||||
|
"/snap/bin" \
|
||||||
|
|
||||||
|
path_append \
|
||||||
|
"${HOME}/bin" \
|
||||||
|
"${HOME}/.bin" \
|
||||||
|
"${HOME}/.local/bin" \
|
||||||
|
"${HOME}/.local/sbin" \
|
||||||
|
"${HOME}/.brew/bin" \
|
||||||
|
"${GOPATH}/bin"
|
||||||
|
export PATH
|
||||||
|
|
||||||
|
# add cargo bin to path
|
||||||
|
if [ -f "$HOME/.cargo/env" ] || [ -r "$HOME/.cargo/env" ]; then
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
. "$HOME/.cargo/env"
|
||||||
|
fi
|
||||||
|
|
||||||
|
export NVM_DIR="$HOME/.nvm"
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"
|
||||||
|
|
||||||
|
# xrandr --setprovideroutputsource 1 0 --setprovideroutputsource 2 0
|
||||||
|
|
||||||
|
# Configure Displays
|
||||||
|
three-mon
|
||||||
|
# xrandr --newmode "1600x900_60.00" 119.00 1600 1696 1864 2128 900 901 904 932 -HSync +Vsync
|
||||||
|
# xrandr --addmode DVI-I-1-1 "1600x900_60.00"
|
||||||
|
# xrandr --above DP-1 --output DVI-I-1-1 --auto --mode "1600x900_60.00" --left-of DP-1
|
||||||
|
|
||||||
|
# Wallpaper Diashows
|
||||||
|
# wp-dia hor eDP-1 10m
|
||||||
|
# wp-dia wp-repo-1 HDMI-1 10m
|
||||||
|
# wp-dia wp-repo-1 DP-1 10m
|
||||||
|
|
||||||
|
updatebar
|
||||||
|
|
||||||
|
picom &
|
||||||
|
|
||||||
|
nohup startlxde 2>/dev/null 1>&2 & disown
|
||||||
|
while true ; do
|
||||||
|
dwm 2>>/home/tosuman/.xinit.log 1>&2
|
||||||
sleep 0.5
|
sleep 0.5
|
||||||
done
|
done
|
||||||
|
|
314
.bashrc
314
.bashrc
|
@ -6,15 +6,15 @@
|
||||||
# Exit when noninteractive. This is more portable than checking PS1.
|
# Exit when noninteractive. This is more portable than checking PS1.
|
||||||
[ "${-#*i}" = "${-}" ] && return
|
[ "${-#*i}" = "${-}" ] && return
|
||||||
|
|
||||||
######################## utils (posix) (thanks rwxrob) #########################
|
############################ utils (thanks rwxrob) #############################
|
||||||
_path_lookup () { type -P "${1-}" ; } # adapted for bash.
|
_path_lookup () { type -P "$1" ; } # adapted for bash.
|
||||||
_have_all () { while [ "${#}" -gt "0" ] ; do [ -x "$(_path_lookup "${1-}")" ] || return 1 ; shift ; done ; }
|
_have_all () { while [ $# -gt 0 ] ; do [ -x "$(_path_lookup "$1")" ] || return 1 ; shift ; done ; }
|
||||||
_have () { _have_all "${1-}" ; }
|
_have () { _have_all "$1" ; }
|
||||||
_source_if () { [ -f "${1-}" ] && [ -r "${1-}" ] && . "${1-}" ; }
|
_source_if () { [ -f "$1" ] && [ -r "$1" ] && . "$1" ; }
|
||||||
|
|
||||||
# TODO: Create ~/.local/bin directory and add ~/.local/bin to PATH
|
# TODO: Create ~/.local/bin directory and add ~/.local/bin to PATH
|
||||||
# Add some basic scripts, like log.log, etc.
|
# Add some basic scripts, like log.log, etc.
|
||||||
############################ logging utils (posix) #############################
|
################################ logging utils #################################
|
||||||
log.log () {
|
log.log () {
|
||||||
case "${1-}" in
|
case "${1-}" in
|
||||||
red) __ansi='41;30' ;;
|
red) __ansi='41;30' ;;
|
||||||
|
@ -52,31 +52,211 @@ __ALL_COMMANDS=("${__COMMANDS[@]}" . : g++ firewall-cmd apt-get xdg-open) # name
|
||||||
2>/dev/null \unalias -- "${__ALL_COMMANDS[@]}"
|
2>/dev/null \unalias -- "${__ALL_COMMANDS[@]}"
|
||||||
hash -r
|
hash -r
|
||||||
unalias -a
|
unalias -a
|
||||||
unset -v POSIXLY_CORRECT
|
unset POSIXLY_CORRECT
|
||||||
|
|
||||||
|
################################# environment ##################################
|
||||||
|
export EDITOR="$({ type -P nvim ||
|
||||||
|
type -P vim ||
|
||||||
|
type -P vi ||
|
||||||
|
type -P nvi ||
|
||||||
|
type -P hx ||
|
||||||
|
type -P nano ||
|
||||||
|
type -P ex ||
|
||||||
|
type -P ed ; } 2>/dev/null)"
|
||||||
|
export GIT_SSH_COMMAND='ssh -oIdentitiesOnly=yes -F"${HOME-}"/.ssh/config'
|
||||||
|
export LANG='en_US.UTF-8'
|
||||||
|
export USER="${USER:-$(whoami)}"
|
||||||
|
export VISUAL="${EDITOR-}"
|
||||||
|
export SUDO_EDITOR="${EDITOR-}"
|
||||||
|
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
|
||||||
|
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"
|
||||||
|
export GIT_CONFIG_GLOBAL="$HOME/.gitconfig"
|
||||||
|
export GPG_TTY="$(tty)"
|
||||||
|
export _JAVA_AWT_WM_NONREPARENTING="1"
|
||||||
|
export USER42="tischmid"
|
||||||
|
export EMAIL42="timo42@proton.me"
|
||||||
|
export MAIL="timo42@proton.me"
|
||||||
|
export GOPATH="$HOME/go"
|
||||||
|
export MANPAGER='nvim +Man!'
|
||||||
|
# export MANPAGER='less -X'
|
||||||
|
export BAT_THEME='gruvbox-dark'
|
||||||
|
# export BAT_THEME='gruvbox-light'
|
||||||
|
export PATH
|
||||||
|
export LD_LIBRARY_PATH
|
||||||
|
|
||||||
|
if ! [ -n "${USER-}" ] ; then
|
||||||
|
if ! USER="$(2>/dev/null ps -o user= -p "${$}" | awk '{print $1}')" ; then
|
||||||
|
if ! USER="$(2>/dev/null whoami)" ; then
|
||||||
|
if ! USER="$(2>/dev/null id -u -n)"; then
|
||||||
|
if ! USER="$(basename -- "$(HOME=~ && printf %s "${HOME}")")" ; then
|
||||||
|
if ! USER="$(2>/dev/null logname)" ; then
|
||||||
|
if USER="${LOGNAME-}" ; [ -z "${USER}" ] ; then
|
||||||
|
unset USER
|
||||||
|
fi; fi; fi; fi; fi; fi; fi
|
||||||
|
|
||||||
|
if ! [ -n "${HOME-}" ] ; then
|
||||||
|
if ! HOME="$(getent passwd "$(id -u "${USER}")" | cut -d: -f6)" ; then
|
||||||
|
if ! HOME="$(getent passwd "${UID}" | cut -d: -f6)" ; then
|
||||||
|
if ! HOME="$(awk -v FS=':' -v user="${USER}" '($1==user) {print $6}' "/etc/passwd")" ; then
|
||||||
|
unset HOME
|
||||||
|
HOME=~
|
||||||
|
if [ "${HOME}" = "~" ] ; then
|
||||||
|
if ! mkdir "/tmp/${USER}" && HOME="/tmp/${USER}" ; then
|
||||||
|
unset HOME
|
||||||
|
fi; fi ; fi ; fi ; fi; fi
|
||||||
|
|
||||||
####################### per session environment (posix) ########################
|
|
||||||
[ -n "${DISPLAY-}" ] || log.warn 'DISPLAY not set'
|
[ -n "${DISPLAY-}" ] || log.warn 'DISPLAY not set'
|
||||||
BAT_THEME='gruvbox-dark' # BAT_THEME='gruvbox-light'
|
|
||||||
GPG_TTY="$(tty)"
|
|
||||||
|
|
||||||
if [ ! "${TERM-}" = "linux" ] ; then
|
if [ ! "${TERM-}" = "linux" ] ; then
|
||||||
__scope () {
|
if [ -f '/usr/share/terminfo/x/xterm-256color' ] ; then
|
||||||
test -f '/usr/share/terminfo/x/xterm-256color' && TERM='xterm-256color' && return
|
export TERM='xterm-256color'
|
||||||
test -f '/usr/share/terminfo/x/xterm-color' && TERM='xterm-color' && return
|
elif [ -f '/usr/share/terminfo/x/xterm-color' ] ; then
|
||||||
test -f '/usr/share/terminfo/x/xterm' && TERM='xterm' && return
|
export TERM='xterm-color'
|
||||||
test -f '/usr/share/terminfo/s/screen-256color' && TERM='screen-256color' && return
|
elif [ -f '/usr/share/terminfo/x/xterm' ] ; then
|
||||||
test -f '/usr/share/terminfo/s/screen' && TERM='screen' && return
|
export TERM='xterm'
|
||||||
return 1
|
elif [ -f '/usr/share/terminfo/s/screen-256color' ] ; then
|
||||||
}
|
export TERM='screen-256color'
|
||||||
__scope
|
elif [ -f '/usr/share/terminfo/s/screen' ] ; then
|
||||||
unset -f __scope
|
export TERM='screen'
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ensure exported
|
######################## path append & prepend (posix) #########################
|
||||||
export USER HOME PWD PATH LD_LIBRARY_PATH TERM LANG DISPLAY EDITOR VISUAL \
|
pathvarprepend () {
|
||||||
XDG_RUNTIME_DIR MAIL GOPATH SUDO_EDITOR SSH_AUTH_SOCK MANPAGER \
|
# prepending paths to pathvar denoted by the expansion of the PATHVAR parameter
|
||||||
GIT_SSH_COMMAND GIT_CONFIG_GLOBAL GPG_TTY BAT_THEME _JAVA_AWT_WM_NONREPARENTING \
|
# if it's already in the PATH, move it to the end
|
||||||
USER42 EMAIL42
|
# POSIX compliant version
|
||||||
|
|
||||||
|
test $# -ge 2 ||
|
||||||
|
{ log.info "Usage: pathvarprepend PATHVAR PATH_TO_ADD [PATH_TO_ADD...]" ;
|
||||||
|
log.info "Example: pathvarprepend LD_LIBRARY_PATH '$HOME/.local/lib' '/usr/local/lib'" ;
|
||||||
|
return 2 ; }
|
||||||
|
|
||||||
|
pathvar=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
case $pathvar in (*[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*|""|[0123456789]*) false;; esac ||
|
||||||
|
{ log.err 'Expanded pathvar is not a valid name/variable identifier' ; return 3 ; }
|
||||||
|
|
||||||
|
if [ "$pathvar" = "PATH" ] ; then
|
||||||
|
test "${-#*r}" = $- ||
|
||||||
|
{ log.err 'Restricted shell, cannot change PATH' ; return 4 ; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
path_prepend_error=0
|
||||||
|
|
||||||
|
# Thanks Stephane
|
||||||
|
code='set -- dummy'
|
||||||
|
n=$#
|
||||||
|
while [ "$n" -gt 0 ] ; do
|
||||||
|
code="$code \"\${$n}\""
|
||||||
|
n=$((n - 1))
|
||||||
|
done
|
||||||
|
eval "$code"
|
||||||
|
|
||||||
|
while shift ; [ $# -gt 0 ] ; do
|
||||||
|
norm_path_to_add=$1
|
||||||
|
|
||||||
|
test "${norm_path_to_add#*:}" = "$norm_path_to_add" ||
|
||||||
|
{ log.warn "Cannot add path with colon: $norm_path_to_add" ; path_prepend_error=1 ; continue ; }
|
||||||
|
|
||||||
|
test -d "$norm_path_to_add" ||
|
||||||
|
{ log.warn "path_to_add ('$norm_path_to_add') not a directory" ; path_prepend_error=1 ; continue ; }
|
||||||
|
|
||||||
|
norm_path=$(printf %s ":$(eval "printf %s "'"'"\$$pathvar"'"'):" | head -n 1 | sed 's|/\+|/|g; s/\/$//; s/:/::/g') # fence with colons, ensure one line, deduplicate slashes, trim trailing, duplicate colons
|
||||||
|
norm_path_to_add=$(printf %s "$norm_path_to_add" | head -n 1 | sed 's|/\+|/|g; s/\/$//') # ensure one line, deduplicate slashes, trim trailing
|
||||||
|
exec 3<<- 'EOF'
|
||||||
|
# escape BRE meta-characters
|
||||||
|
s/\\/\\./g # backslash first
|
||||||
|
s/\./\\./g
|
||||||
|
s/\^/\\^/g
|
||||||
|
s/\$/\\$/g
|
||||||
|
s/\*/\\*/g
|
||||||
|
s/\[/\\[/g
|
||||||
|
s|/|\\/|g # escape delimiter for outer sed
|
||||||
|
EOF
|
||||||
|
norm_path=$(printf %s "$norm_path" | sed "s/:$(printf %s "$norm_path_to_add" | sed -f /proc/self/fd/3 3<&3)://g") # remove all instances of PATH_TO_ADD from PATH
|
||||||
|
exec 3<&-
|
||||||
|
norm_path=$(printf %s "$norm_path" | sed 's/:\+/:/g; s/^://; s/:$//') # deduplicate colons, trim leading and trailing
|
||||||
|
eval "$pathvar=\$norm_path_to_add\${norm_path:+:\$norm_path}" # prepend with colon
|
||||||
|
done
|
||||||
|
return $path_prepend_error
|
||||||
|
}
|
||||||
|
|
||||||
|
pathvarappend () {
|
||||||
|
# appending paths to pathvar denoted by the expansion of the PATHVAR parameter
|
||||||
|
# if it's already in the PATH, move it to the end
|
||||||
|
# POSIX compliant version
|
||||||
|
|
||||||
|
test $# -ge 2 ||
|
||||||
|
{ log.info "Usage: pathvarappend PATHVAR PATH_TO_ADD [PATH_TO_ADD...]"
|
||||||
|
log.info "Example: pathvarappend LD_LIBRARY_PATH '$HOME/.local/lib' '/usr/local/lib'"
|
||||||
|
return 2 ; }
|
||||||
|
|
||||||
|
pathvar=$1
|
||||||
|
|
||||||
|
case $pathvar in (*[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*|""|[0123456789]*) false;; esac ||
|
||||||
|
{ log.err 'Expanded pathvar is not a valid name/variable identifier' ; return 3 ; }
|
||||||
|
|
||||||
|
if [ "$pathvar" = "PATH" ] ; then
|
||||||
|
test "${-#*r}" = $- ||
|
||||||
|
{ log.err 'Restricted shell, cannot change PATH' ; return 4 ; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
path_append_error=0
|
||||||
|
|
||||||
|
while shift ; [ $# -gt 0 ] ; do
|
||||||
|
norm_path_to_add=$1
|
||||||
|
|
||||||
|
test "${norm_path_to_add#*:}" = "$norm_path_to_add" ||
|
||||||
|
{ log.warn 'Cannot add path with colon' ; path_append_error=1 ; continue ; }
|
||||||
|
|
||||||
|
test -d "$norm_path_to_add" ||
|
||||||
|
{ log.warn "path_to_add ('$norm_path_to_add') not a directory" ; path_append_error=1 ; continue ; }
|
||||||
|
|
||||||
|
norm_path=$(printf %s ":$(eval "printf %s "'"'"\$$pathvar"'"'):" | head -n 1 | sed 's|/\+|/|g; s/\/$//; s/:/::/g') # fence with colons, ensure one line, deduplicate slashes, trim trailing, duplicate colons
|
||||||
|
norm_path_to_add=$(printf %s "$norm_path_to_add" | head -n 1 | sed 's|/\+|/|g; s/\/$//') # ensure one line, deduplicate slashes, trim trailing
|
||||||
|
exec 3<<- 'EOF'
|
||||||
|
# escape BRE meta-characters
|
||||||
|
s/\\/\\./g # backslash first
|
||||||
|
s/\./\\./g
|
||||||
|
s/\^/\\^/g
|
||||||
|
s/\$/\\$/g
|
||||||
|
s/\*/\\*/g
|
||||||
|
s/\[/\\[/g
|
||||||
|
s|/|\\/|g # escape delimiter for outer sed
|
||||||
|
EOF
|
||||||
|
norm_path=$(printf %s "$norm_path" | sed "s/:$(printf %s "$norm_path_to_add" | sed -f /proc/self/fd/3 3<&3)://g") # remove all instances of PATH_TO_ADD from PATH
|
||||||
|
exec 3<&-
|
||||||
|
norm_path=$(printf %s "$norm_path" | sed 's/:\+/:/g; s/^://; s/:$//') # deduplicate colons, trim leading and trailing
|
||||||
|
eval "$pathvar=\${norm_path:+\$norm_path:}\$norm_path_to_add" # append with colon
|
||||||
|
done
|
||||||
|
return $path_append_error
|
||||||
|
}
|
||||||
|
|
||||||
|
path_append () {
|
||||||
|
pathvarappend PATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
ld_lib_path_append () {
|
||||||
|
pathvarappend LD_LIBRARY_PATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
cdpath_append () {
|
||||||
|
pathvarappend CDPATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
path_prepend () {
|
||||||
|
pathvarprepend PATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
ld_lib_path_prepend () {
|
||||||
|
pathvarprepend LD_LIBRARY_PATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
cdpath_prepend () {
|
||||||
|
pathvarprepend CDPATH "$@"
|
||||||
|
}
|
||||||
|
|
||||||
################################# bash options #################################
|
################################# bash options #################################
|
||||||
shopt -s autocd
|
shopt -s autocd
|
||||||
|
@ -147,7 +327,6 @@ alias watch='watch -tcn.1 ' # trailing space means complete aliases
|
||||||
|
|
||||||
########################## overwrite aliases (posix) ###########################
|
########################## overwrite aliases (posix) ###########################
|
||||||
alias make='compiledb make'
|
alias make='compiledb make'
|
||||||
alias cat='bat'
|
|
||||||
|
|
||||||
########################## navigation aliases (posix) ##########################
|
########################## navigation aliases (posix) ##########################
|
||||||
alias r='ranger'
|
alias r='ranger'
|
||||||
|
@ -163,13 +342,13 @@ alias wttr='curl -sfkSL wttr.in'
|
||||||
alias ipa='ip -br -color=auto a'
|
alias ipa='ip -br -color=auto a'
|
||||||
alias xcopy='xsel --clipboard --input'
|
alias xcopy='xsel --clipboard --input'
|
||||||
alias xpaste='xsel --clipboard --output'
|
alias xpaste='xsel --clipboard --output'
|
||||||
alias paco='"${HOME-}/francinette/tester.sh"'
|
alias paco='"${HOME-}"/francinette/tester.sh'
|
||||||
alias pcker='nvim "${HOME-}/.config/nvim/lua/"*'
|
alias pcker='nvim "${HOME-}"/.config/nvim/lua/*'
|
||||||
alias francinette='"${HOME-}/francinette/tester.sh"'
|
alias francinette='"${HOME-}"/francinette/tester.sh'
|
||||||
alias q-dig='docker run --rm -it ghcr.io/natesales/q'
|
alias q-dig='docker run --rm -it ghcr.io/natesales/q'
|
||||||
alias q='duck'
|
alias q='duck'
|
||||||
alias after='nvim "${HOME-}/.config/nvim/after/plugin"'
|
alias after='nvim "${HOME-}"/.config/nvim/after/plugin'
|
||||||
alias dotconf='git --git-dir="${HOME-}/.dotfiles/" --work-tree="${HOME-}"'
|
alias dotconf='git --git-dir="${HOME-}"/.dotfiles/ --work-tree="${HOME-}"'
|
||||||
alias ll='\ls --width="${COLUMNS:-80}" --sort=time --time=mtime --color=auto --fu -bharZ1l'
|
alias ll='\ls --width="${COLUMNS:-80}" --sort=time --time=mtime --color=auto --fu -bharZ1l'
|
||||||
alias l='\ls --width="${COLUMNS:-80}" --sort=time --time=mtime --color=auto --time-style=long-iso -bharZ1l'
|
alias l='\ls --width="${COLUMNS:-80}" --sort=time --time=mtime --color=auto --time-style=long-iso -bharZ1l'
|
||||||
alias colors='bash -c "$(curl -sfkSL "https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw")"'
|
alias colors='bash -c "$(curl -sfkSL "https://gist.githubusercontent.com/HaleTom/89ffe32783f89f403bba96bd7bcd1263/raw")"'
|
||||||
|
@ -192,17 +371,17 @@ vix () {
|
||||||
|
|
||||||
[ "${#}" -lt "1" ] && { log.info "Usage: vix FILE [VIM_ARGS...]" ; return 1 ; }
|
[ "${#}" -lt "1" ] && { log.info "Usage: vix FILE [VIM_ARGS...]" ; return 1 ; }
|
||||||
|
|
||||||
file="${1-}"
|
file="${1}"
|
||||||
shift
|
shift
|
||||||
[ -e "${file}" ] && [ ! -f "${file}" ] && { log.err "File '${file}' exists and is not a regular file" ; return 2 ; }
|
[ -e "$file" ] && [ ! -f "$file" ] && { log.err "File '$file' exists and is not a regular file" ; return 2 ; }
|
||||||
if [ ! -e "${file}" ] ; then
|
if [ ! -e "$file" ] ; then
|
||||||
printf "#! /bin/sh -\n\n\n" > "${file}" || { log.err "Can't write to file '${file}'" ; return 3 ; }
|
printf "#! /bin/sh -\n\n\n" > "$file" || { log.err "Can't write to file '$file'" ; return 3 ; }
|
||||||
set -- "${@}" +3
|
set -- "$@" +3
|
||||||
fi
|
fi
|
||||||
if [ ! -x "${file}" ] ; then
|
if [ ! -x "$file" ] ; then
|
||||||
chmod +x "${file}" || { log.err "Can't chmod +x '${file}'" ; return 4 ; }
|
chmod +x "$file" || { log.err "Can't chmod +x '$file'" ; return 4 ; }
|
||||||
fi
|
fi
|
||||||
vi "${@}" "${file}"
|
vi "$@" "$file"
|
||||||
}
|
}
|
||||||
|
|
||||||
##################### cd with pushd functionality (posix) ######################
|
##################### cd with pushd functionality (posix) ######################
|
||||||
|
@ -218,11 +397,11 @@ cd () {
|
||||||
vimw () {
|
vimw () {
|
||||||
_have vi || { log.err 'vi missing' ; exit 1 ; }
|
_have vi || { log.err 'vi missing' ; exit 1 ; }
|
||||||
|
|
||||||
[ -z "${1-}" ] && { log.info "Usage: vimw FILE [VIM_ARGS...]" ; return 1 ; }
|
[ -z "$1" ] && { log.info "Usage: vimw FILE [VIM_ARGS...]" ; return 1 ; }
|
||||||
|
|
||||||
first="${1-}"
|
first="$1"
|
||||||
shift
|
shift
|
||||||
vi "${@}" "$(type -P "${first}")"
|
vi "$@" "$(type -P "$first")"
|
||||||
}
|
}
|
||||||
|
|
||||||
#################################### paruuu (posix) ####################################
|
#################################### paruuu (posix) ####################################
|
||||||
|
@ -305,15 +484,15 @@ skill () {
|
||||||
exit_status=0
|
exit_status=0
|
||||||
while [ -n "${1-}" ] ; do
|
while [ -n "${1-}" ] ; do
|
||||||
# pids="$(ps -eo pid,cmd)"
|
# pids="$(ps -eo pid,cmd)"
|
||||||
# pids="$(echo "${pids}" | cut -d " " -f3- | grep -n -- "${1-}" | cut -d ":" -f1 | awk 'BEGIN{printf "NR=="}ORS="||NR=="' | head -n 1 | pids="${pids}" xargs --no-run-if-empty -I {} bash -c 'echo "${pids}" | cut -d " " -f2 | awk "${1-}0"' bash {})"
|
# pids="$(echo "$pids" | cut -d " " -f3- | grep -n -- "$1" | cut -d ":" -f1 | awk 'BEGIN{printf "NR=="}ORS="||NR=="' | head -n 1 | pids="$pids" xargs --no-run-if-empty -I {} bash -c 'echo "$pids" | cut -d " " -f2 | awk "${1}0"' bash {})"
|
||||||
pgrep -f -- "${1-}" | xargs -r kill -9 && return 0 || {
|
pgrep -f -- "$1" | xargs -r kill -9 && return 0 || {
|
||||||
printf '\033[31m%s\033[m\n' "These processes couldn't be killed without sudo:"
|
printf '\033[31m%s\033[m\n' "These processes couldn't be killed without sudo:"
|
||||||
pgrep -f "${1-}" | xargs ps -o user,ruser,pid,c,stime,tty,time,cmd
|
pgrep -f "$1" | xargs ps -o user,ruser,pid,c,stime,tty,time,cmd
|
||||||
}
|
}
|
||||||
pgrep -f -- "${1-}" | sudo xargs -r kill -9 || {
|
pgrep -f -- "$1" | sudo xargs -r kill -9 || {
|
||||||
if [ "${?}" -ne "1" ] ; then
|
if [ $? -ne 1 ] ; then
|
||||||
printf '\033[41;30m%s\033[m\n' "These processes couldn't be killed with root (sudo):"
|
printf '\033[41;30m%s\033[m\n' "These processes couldn't be killed with root (sudo):"
|
||||||
pgrep -f "${1-}" | xargs ps -o user,ruser,pid,c,stime,tty,time,cmd
|
pgrep -f "$1" | xargs ps -o user,ruser,pid,c,stime,tty,time,cmd
|
||||||
else
|
else
|
||||||
log.info Cancelled
|
log.info Cancelled
|
||||||
return 3 ;
|
return 3 ;
|
||||||
|
@ -322,7 +501,7 @@ skill () {
|
||||||
}
|
}
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
return "${exit_status}"
|
return $exit_status
|
||||||
}
|
}
|
||||||
|
|
||||||
############################# wpa_restart (posix) ##############################
|
############################# wpa_restart (posix) ##############################
|
||||||
|
@ -343,8 +522,8 @@ bat () {
|
||||||
|
|
||||||
################################# take (posix) #################################
|
################################# take (posix) #################################
|
||||||
take () {
|
take () {
|
||||||
mkdir -p -- "${1-}" &&
|
mkdir -p -- "$1" &&
|
||||||
cd -P -- "${1-}" ||
|
cd -P -- "$1" ||
|
||||||
return 1 ;
|
return 1 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +561,7 @@ __norm () {
|
||||||
# Depends on git, norminette
|
# Depends on git, norminette
|
||||||
ft_check () {
|
ft_check () {
|
||||||
# Set params
|
# Set params
|
||||||
URL="${1-}"
|
URL="${1}"
|
||||||
DIR="/tmp/tmp_repo_$(date +%s)"
|
DIR="/tmp/tmp_repo_$(date +%s)"
|
||||||
|
|
||||||
_have git || { log.err 'git missing' ; return 1 ; }
|
_have git || { log.err 'git missing' ; return 1 ; }
|
||||||
|
@ -411,8 +590,8 @@ ft_check () {
|
||||||
############################### clone42 (posix) ################################
|
############################### clone42 (posix) ################################
|
||||||
# Depends on git, norminette
|
# Depends on git, norminette
|
||||||
clone42 () {
|
clone42 () {
|
||||||
folder="${1-}"
|
folder="${1}"
|
||||||
repo_url="${2-}"
|
repo_url="${2}"
|
||||||
|
|
||||||
_have git || { log.err 'git missing' ; return 1 ; }
|
_have git || { log.err 'git missing' ; return 1 ; }
|
||||||
_have norminette || { log.err 'norminette missing' ; return 2 ; }
|
_have norminette || { log.err 'norminette missing' ; return 2 ; }
|
||||||
|
@ -424,11 +603,11 @@ clone42 () {
|
||||||
}
|
}
|
||||||
|
|
||||||
################################ bash pre-exec #################################
|
################################ bash pre-exec #################################
|
||||||
if [ ! -f "${HOME}/.bash-preexec.sh" ] ; then
|
if [ ! -f "${HOME}"/.bash-preexec.sh ] ; then
|
||||||
curl -sfkSL "https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh" -o "${HOME}/.bash-preexec.sh"
|
curl -sfkSL "https://raw.githubusercontent.com/rcaloras/bash-preexec/master/bash-preexec.sh" -o "${HOME}"/.bash-preexec.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
. "${HOME}/.bash-preexec.sh"
|
. "${HOME}"/.bash-preexec.sh
|
||||||
|
|
||||||
preexec() {
|
preexec() {
|
||||||
[ -d "${HISTDIR}" ] || { mkdir -p -- "${HISTDIR}" || log.warn "Can't create directory: ${HISTDIR}" ; }
|
[ -d "${HISTDIR}" ] || { mkdir -p -- "${HISTDIR}" || log.warn "Can't create directory: ${HISTDIR}" ; }
|
||||||
|
@ -458,8 +637,8 @@ precmd() {
|
||||||
#################################### prompt ####################################
|
#################################### prompt ####################################
|
||||||
GIT_PS1_SHOWDIRTYSTATE='1'
|
GIT_PS1_SHOWDIRTYSTATE='1'
|
||||||
GIT_PROMPT='1'
|
GIT_PROMPT='1'
|
||||||
if [ ! -f "${HOME}/git-prompt.sh" ] && [ "${GIT_PROMPT-}" -eq "1" ] ; then
|
if [ ! -f "${HOME}"/git-prompt.sh ] && [ "${GIT_PROMPT-}" -eq "1" ] ; then
|
||||||
curl -sfkSL "https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh" -o "${HOME}/git-prompt.sh"
|
curl -sfkSL "https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh" -o "${HOME}"/git-prompt.sh
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_PS1_CWD_CLR='\[\033[33m\]'
|
_PS1_CWD_CLR='\[\033[33m\]'
|
||||||
|
@ -482,9 +661,9 @@ _PS1_GIT='\[\033[m\]\[\033[36m\]$(__git_ps1 " (%s)")'
|
||||||
# _PS1_2='\[\033[m\]\[\033[36m\]$(__norm)\[\033[m\]\n\[\033[35m\]~\$\[\033[m\] '
|
# _PS1_2='\[\033[m\]\[\033[36m\]$(__norm)\[\033[m\]\n\[\033[35m\]~\$\[\033[m\] '
|
||||||
_PS1_2='\[\033[m\]\[\033[36m\]\[\033[m\]\n\[\033[35m\]~\$\[\033[m\] '
|
_PS1_2='\[\033[m\]\[\033[36m\]\[\033[m\]\n\[\033[35m\]~\$\[\033[m\] '
|
||||||
|
|
||||||
if [ -f "${HOME}/git-prompt.sh" ] && [ -r "${HOME}/git-prompt.sh" ] && \
|
if [ -f "${HOME}"/git-prompt.sh ] && [ -r "${HOME}"/git-prompt.sh ] && \
|
||||||
[ "${GIT_PROMPT-}" -eq "1" ] ; then
|
[ "${GIT_PROMPT-}" -eq "1" ] ; then
|
||||||
. "${HOME}/git-prompt.sh"
|
. "${HOME}"/git-prompt.sh
|
||||||
PS1="${_PS1_1-}${_PS1_GIT-}${_PS1_2-}"
|
PS1="${_PS1_1-}${_PS1_GIT-}${_PS1_2-}"
|
||||||
else
|
else
|
||||||
PS1="${_PS1_1-}${_PS1_2-}"
|
PS1="${_PS1_1-}${_PS1_2-}"
|
||||||
|
@ -501,8 +680,7 @@ fi
|
||||||
# PS1='[${SHLVL}] '"${PS1}"
|
# PS1='[${SHLVL}] '"${PS1}"
|
||||||
|
|
||||||
# ##################################### aoc ######################################
|
# ##################################### aoc ######################################
|
||||||
# TODO: put into script
|
AOC_DIR="${HOME}/projects/aoc" # remember to change this to whatever your AOC directory is
|
||||||
export AOC_DIR="${HOME}/projects/aoc" # remember to change this to whatever your AOC directory is
|
|
||||||
alias aos='< in.txt python3 solution.py'
|
alias aos='< in.txt python3 solution.py'
|
||||||
alias aot='< test.txt printf '\033[34m' ; python3 solution.py ; printf '\033[m''
|
alias aot='< test.txt printf '\033[34m' ; python3 solution.py ; printf '\033[m''
|
||||||
alias aoc='aot ; echo ; aos'
|
alias aoc='aot ; echo ; aos'
|
||||||
|
@ -520,17 +698,17 @@ aocload () {
|
||||||
|
|
||||||
this_year="$(date "+%Y")"
|
this_year="$(date "+%Y")"
|
||||||
this_day="$(date "+%d" | sed -e 's/^0//')"
|
this_day="$(date "+%d" | sed -e 's/^0//')"
|
||||||
if [ -n "${1-}" ] ; then
|
if [ -n "${1}" ] ; then
|
||||||
if [ -z "${2-}" ] ; then
|
if [ -z "${2}" ] ; then
|
||||||
printf '\033[31m%s\033[m\n' 'Expected one more parameter (day)'
|
printf '\033[31m%s\033[m\n' 'Expected one more parameter (day)'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if [ -n "${3-}" ] ; then
|
if [ -n "${3}" ] ; then
|
||||||
printf '\033[31m%s\033[m\n' 'Expected exactly 2 parameters (year day)'
|
printf '\033[31m%s\033[m\n' 'Expected exactly 2 parameters (year day)'
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
year="${1-}"
|
year="${1}"
|
||||||
day="${2-}"
|
day="${2}"
|
||||||
if [ "${day}" -lt "1" -o "${day}" -gt "25" ] ; then
|
if [ "${day}" -lt "1" -o "${day}" -gt "25" ] ; then
|
||||||
printf '\033[31m%s\033[m\n' 'Day not in range 1..25'
|
printf '\033[31m%s\033[m\n' 'Day not in range 1..25'
|
||||||
return 3
|
return 3
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
#! /bin/sh -
|
|
||||||
exec xrandr --output HDMI-1 --auto --output DP-1 --right-of HDMI-1 --auto
|
|
|
@ -1,2 +0,0 @@
|
||||||
#! /bin/sh -
|
|
||||||
exec xrandr --output eDP-1 --auto --output DP-1 --above eDP-1 --auto
|
|
|
@ -1,10 +0,0 @@
|
||||||
#! /bin/sh -
|
|
||||||
|
|
||||||
if [ -t 0 ] && [ -n "${1}" ]; then
|
|
||||||
while [ -n "${1}" ]; do
|
|
||||||
printf '%s\n' "${1}" | sed 's/\\/\\\\/g; s/"/"'"'"'"'"'"'"/g; s/^/"/; s/$/"/'
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
else
|
|
||||||
sed 's/\\/\\\\/g; s/"/"'"'"'"'"'"'"/g; s/^/"/; s/$/"/'
|
|
||||||
fi
|
|
|
@ -1,31 +0,0 @@
|
||||||
#! /bin/bash --
|
|
||||||
|
|
||||||
command -v lynx >/dev/null 2>&1 || { echo "Need lynx"; exit 1; }
|
|
||||||
|
|
||||||
urlencode () {
|
|
||||||
local str="$*"
|
|
||||||
local encoded=
|
|
||||||
local i c x
|
|
||||||
for (( i=0; i < ${#str}; ++i )); do
|
|
||||||
c=${str:$i:1}
|
|
||||||
case "$c" in
|
|
||||||
[-_.~a-zA-Z0-9] ) x="$c" ;;
|
|
||||||
* ) printf -v x '%%%02x' "'$c" ;;
|
|
||||||
esac
|
|
||||||
encoded+="$x"
|
|
||||||
done
|
|
||||||
printf %s "$encoded"
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ -t 0 ]; then
|
|
||||||
query=$(urlencode "$*")
|
|
||||||
dump=
|
|
||||||
else
|
|
||||||
query=$(urlencode "$(tr -d '\n')")
|
|
||||||
dump="-dump"
|
|
||||||
fi
|
|
||||||
|
|
||||||
base="https://duckduckgo.com/lite?q="
|
|
||||||
[ "$0" = "ggl" ] && base="https://www.google.com/search?q="
|
|
||||||
|
|
||||||
exec lynx $dump "$base$query"
|
|
|
@ -1,2 +0,0 @@
|
||||||
#! /bin/sh -
|
|
||||||
exec xrandr --output eDP-1 --auto --output HDMI-1 --above eDP-1 --auto
|
|
File diff suppressed because one or more lines are too long
|
@ -1,23 +0,0 @@
|
||||||
#! /bin/sh -
|
|
||||||
|
|
||||||
if [ "${0##*/}" = "log.log" ] ; then
|
|
||||||
case "${1-}" in
|
|
||||||
red) ansi='41;30' ;;
|
|
||||||
orange) ansi='43;30' ;;
|
|
||||||
blue) ansi='44;30' ;;
|
|
||||||
green) ansi='42;30' ;;
|
|
||||||
*) ansi='45;30' ;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
1>&2 printf "\033[${ansi}m%s\033[m\n" "${*}"
|
|
||||||
unset ansi
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "${0##*/}" in
|
|
||||||
log.err) log.log red "${@}" ;;
|
|
||||||
log.warn) log.log orange "${@}" ;;
|
|
||||||
log.info) log.log blue "${@}" ;;
|
|
||||||
log.good) log.log green "${@}" ;;
|
|
||||||
*) log.log nothing "${@}" ;;
|
|
||||||
esac
|
|
|
@ -1,78 +0,0 @@
|
||||||
#! /usr/bin/python3 --
|
|
||||||
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
from subprocess import Popen, PIPE
|
|
||||||
|
|
||||||
def decode(bytes_):
|
|
||||||
return bytes_.decode('utf-8').strip()
|
|
||||||
|
|
||||||
def debug(msg, color='red'):
|
|
||||||
reset = '\033[m'
|
|
||||||
if color == 'red':
|
|
||||||
ansi_code = '\033[31m'
|
|
||||||
elif color == 'green':
|
|
||||||
ansi_code = '\033[32m'
|
|
||||||
elif color == 'yellow':
|
|
||||||
ansi_code = '\033[33m'
|
|
||||||
else:
|
|
||||||
print(f"Unknown color: '{color}'", file=sys.stderr, flush=True)
|
|
||||||
ansi_code = reset
|
|
||||||
print(ansi_code + msg + reset, file=sys.stderr, flush=True)
|
|
||||||
|
|
||||||
def run_bash(cmd):
|
|
||||||
process = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=True)
|
|
||||||
outb, errb = process.communicate()
|
|
||||||
errcode = process.returncode
|
|
||||||
if errcode != 0:
|
|
||||||
debug("There was an error getting the MAC address")
|
|
||||||
sys.exit(1)
|
|
||||||
out = decode(outb).strip()
|
|
||||||
return out
|
|
||||||
|
|
||||||
def get_permaddr():
|
|
||||||
permaddr = run_bash("ip link show wlan0 | grep permaddr | awk '{ print $6 }'")
|
|
||||||
return permaddr
|
|
||||||
|
|
||||||
def main():
|
|
||||||
mac_address = run_bash("ip link show wlan0 | grep link/ether | awk '{ print $2 }'")
|
|
||||||
as_int = int(mac_address.replace(':', ''), 16)
|
|
||||||
set_directly = False
|
|
||||||
if len(sys.argv) == 2:
|
|
||||||
if sys.argv[1] == 'inc':
|
|
||||||
debug("Incrementing MAC address by 1", 'green')
|
|
||||||
as_int += 1
|
|
||||||
elif sys.argv[1] == 'dec':
|
|
||||||
debug("Decrementing MAC address by 1", 'green')
|
|
||||||
as_int -= 1
|
|
||||||
elif sys.argv[1] == 'reset':
|
|
||||||
permaddr = get_permaddr()
|
|
||||||
if not permaddr:
|
|
||||||
debug("MAC address already matches real MAC address, nothing to change", 'yellow')
|
|
||||||
return 0
|
|
||||||
new_mac = permaddr
|
|
||||||
debug(f"Resetting MAC address to {new_mac}", 'green')
|
|
||||||
set_directly = True
|
|
||||||
else:
|
|
||||||
debug(f"Unknown argument: '{sys.argv[1]}'", 'red')
|
|
||||||
debug(f"Must be one of: inc, dec, reset", 'red')
|
|
||||||
sys.exit(2)
|
|
||||||
else:
|
|
||||||
debug("No argument provided. Doing default action", 'yellow')
|
|
||||||
debug("Incrementing MAC address by 1", 'green')
|
|
||||||
as_int += 1
|
|
||||||
if not set_directly:
|
|
||||||
as_hex = hex(as_int)[2:]
|
|
||||||
split_as_hex = []
|
|
||||||
for match in list(re.finditer('..', as_hex[::-1])):
|
|
||||||
split_as_hex.insert(0, match.group()[::-1])
|
|
||||||
new_mac = ':'.join(split_as_hex)
|
|
||||||
commands = f'''
|
|
||||||
sudo sh -c 'ip link set dev wlan0 down ; ip link set dev wlan0 address {new_mac} ; ip link set dev wlan0 up'
|
|
||||||
'''.strip()
|
|
||||||
commands = re.sub('\n\s*', '\n', commands)
|
|
||||||
print(commands)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main())
|
|
|
@ -1,14 +0,0 @@
|
||||||
#! /bin/sh -
|
|
||||||
|
|
||||||
today="$(date +%Y-%m-%d)"
|
|
||||||
note_filename="${HOME}/notes/note-${today}.md"
|
|
||||||
|
|
||||||
if [ ! -f "${note_filename}" ]; then
|
|
||||||
echo "# Notes for ${today}" > "${note_filename}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
nvim -c "norm Go" \
|
|
||||||
-c "norm Go## $(date +%H:%M)" \
|
|
||||||
-c "norm G2o" \
|
|
||||||
-c "norm zz" \
|
|
||||||
-c "startinsert" "${note_filename}"
|
|
|
@ -1,13 +0,0 @@
|
||||||
#! /bin/sh -
|
|
||||||
|
|
||||||
(
|
|
||||||
|
|
||||||
hdmi1_top
|
|
||||||
dp1_right_hdmi1
|
|
||||||
|
|
||||||
sleep 5
|
|
||||||
xwallpaper --output DP-1 --zoom /home/tosuman/Wallpapers/hor/Dune.jpg
|
|
||||||
xwallpaper --output eDP-1 --zoom /home/tosuman/Wallpapers/favs/travellers.jpg
|
|
||||||
xwallpaper --output HDMI-1 --zoom /home/tosuman/Wallpapers/hor/koi.png
|
|
||||||
|
|
||||||
) &
|
|
219
.profile
219
.profile
|
@ -1,223 +1,8 @@
|
||||||
#! /bin/bash --
|
#! /bin/bash --
|
||||||
# ex: set ts=4 sw=4 ft=sh
|
# ex: set ts=4 sw=4 ft=sh
|
||||||
|
|
||||||
# TODO: Make more general purpose, currently quite bashy
|
# shellcheck disable=SC2009
|
||||||
|
|
||||||
############################## global environment ##############################
|
|
||||||
if ! [ -n "${USER-}" ] ; then
|
|
||||||
if ! USER="$(2>/dev/null ps -o user= -p "${$}" | awk '{print $1}')" ; then
|
|
||||||
if ! USER="$(2>/dev/null whoami)" ; then
|
|
||||||
if ! USER="$(2>/dev/null id -u -n)"; then
|
|
||||||
if ! USER="$(basename -- "$({HOME=~ && printf %s "${HOME}")")" ; then
|
|
||||||
if ! USER="$(2>/dev/null logname)" ; then
|
|
||||||
if USER="${LOGNAME-}" ; [ -z "${USER}" ] ; then
|
|
||||||
unset USER
|
|
||||||
fi; fi; fi; fi; fi; fi; fi
|
|
||||||
|
|
||||||
if ! [ -n "${HOME-}" ] ; then
|
|
||||||
if ! HOME="$(getent passwd "$(id -u "${USER}")" | cut -d: -f6)" ; then
|
|
||||||
if ! HOME="$(getent passwd "${UID}" | cut -d: -f6)" ; then
|
|
||||||
if ! HOME="$(awk -v FS=':' -v user="${USER}" '($1==user) {print $6}' "/etc/passwd")" ; then
|
|
||||||
unset HOME
|
|
||||||
HOME=~
|
|
||||||
if [ "${HOME}" = "~" ] ; then
|
|
||||||
if ! mkdir "/tmp/${USER}" && HOME="/tmp/${USER}" ; then
|
|
||||||
unset HOME
|
|
||||||
fi; fi ; fi ; fi ; fi; fi
|
|
||||||
|
|
||||||
export EDITOR="$({ type -P nvim ||
|
|
||||||
type -P vim ||
|
|
||||||
type -P vi ||
|
|
||||||
type -P nvi ||
|
|
||||||
type -P hx ||
|
|
||||||
type -P nano ||
|
|
||||||
type -P ex ||
|
|
||||||
type -P ed ; } 2>/dev/null)"
|
|
||||||
export _JAVA_AWT_WM_NONREPARENTING="1"
|
|
||||||
export GIT_SSH_COMMAND="ssh -oIdentitiesOnly=yes -F"${HOME}"/.ssh/config"
|
|
||||||
export LANG="en_US.UTF-8"
|
|
||||||
export VISUAL="${EDITOR}"
|
|
||||||
export SUDO_EDITOR="${EDITOR}"
|
|
||||||
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
|
|
||||||
export SSH_AUTH_SOCK="${XDG_RUNTIME_DIR}/ssh-agent.socket"
|
|
||||||
export GIT_CONFIG_GLOBAL="${HOME}/.gitconfig"
|
|
||||||
export USER42="tischmid"
|
|
||||||
export EMAIL42="timo42@proton.me"
|
|
||||||
export MAIL="timo42@proton.me"
|
|
||||||
export GOPATH="${HOME}/go"
|
|
||||||
MANPAGER="nvim +Man!" # MANPAGER="less -X"
|
|
||||||
export MANPAGER
|
|
||||||
export PATH
|
|
||||||
export LD_LIBRARY_PATH
|
|
||||||
|
|
||||||
pathvarprepend () {
|
|
||||||
# prepending paths to pathvar denoted by the expansion of the PATHVAR parameter
|
|
||||||
# if it's already in the PATH, move it to the end
|
|
||||||
# POSIX compliant version
|
|
||||||
|
|
||||||
test -n "${2}" ||
|
|
||||||
{ echo "Usage: pathvarprepend PATHVAR PATH_TO_ADD [PATH_TO_ADD...]";
|
|
||||||
echo "Example: pathvarprepend LD_LIBRARY_PATH '${HOME}/.local/lib' '/usr/local/lib'";
|
|
||||||
return 2; }
|
|
||||||
|
|
||||||
pathvar="${1}"
|
|
||||||
shift
|
|
||||||
|
|
||||||
case $pathvar in (*[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*|""|[0123456789]*) false;; esac ||
|
|
||||||
{ echo 'Expanded pathvar is not a valid name/variable identifier'; return 3; }
|
|
||||||
|
|
||||||
if [ "$pathvar" = "PATH" ]; then
|
|
||||||
test "${-#*r}" = "${-}" ||
|
|
||||||
{ echo 'Restricted shell, cannot change PATH'; return 4; }
|
|
||||||
fi
|
|
||||||
|
|
||||||
path_prepend_error=0
|
|
||||||
|
|
||||||
# Thanks Stephane
|
|
||||||
code="set -- dummy"
|
|
||||||
n="${#}"
|
|
||||||
while [ "${n}" -gt 0 ]; do
|
|
||||||
code="$code \"\${${n}}\""
|
|
||||||
n="$((n - 1))"
|
|
||||||
done
|
|
||||||
eval "$code"
|
|
||||||
|
|
||||||
while shift; [ "${#}" -gt 0 ]; do
|
|
||||||
norm_path_to_add="${1}"
|
|
||||||
|
|
||||||
test "${norm_path_to_add#*:}" = "${norm_path_to_add}" ||
|
|
||||||
{ echo 'Cannot add path with colon'; path_prepend_error="1"; continue; }
|
|
||||||
|
|
||||||
test -d "${norm_path_to_add}" ||
|
|
||||||
{ echo "path_to_add ('${norm_path_to_add}') not a directory"; path_prepend_error="1"; continue; }
|
|
||||||
|
|
||||||
norm_path=$(printf %s ":$(eval "printf %s "'"'"\$$pathvar"'"'):" | head -n 1 | sed 's|/\+|/|g; s/\/$//; s/:/::/g') # fence with colons, ensure one line, deduplicate slashes, trim trailing, duplicate colons
|
|
||||||
norm_path_to_add=$(printf %s "$norm_path_to_add" | head -n 1 | sed 's|/\+|/|g; s/\/$//') # ensure one line, deduplicate slashes, trim trailing
|
|
||||||
exec 3<<- 'EOF'
|
|
||||||
# escape BRE meta-characters
|
|
||||||
s/\\/\\./g # backslash first
|
|
||||||
s/\./\\./g
|
|
||||||
s/\^/\\^/g
|
|
||||||
s/\$/\\$/g
|
|
||||||
s/\*/\\*/g
|
|
||||||
s/\[/\\[/g
|
|
||||||
s|/|\\/|g # escape delimiter for outer sed
|
|
||||||
EOF
|
|
||||||
norm_path="$(printf %s "${norm_path}" | sed "s/:$(printf %s "${norm_path_to_add}" | sed -f /proc/self/fd/3 3<&3)://g")" # remove all instances of PATH_TO_ADD from PATH
|
|
||||||
exec 3<&-
|
|
||||||
norm_path="$(printf %s "${norm_path}" | sed 's/:\+/:/g; s/^://; s/:$//')" # deduplicate colons, trim leading and trailing
|
|
||||||
eval "${pathvar}=\$norm_path_to_add\${norm_path:+:\$norm_path}" # prepend with colon
|
|
||||||
done
|
|
||||||
return "${path_prepend_error}"
|
|
||||||
} && export -f pathvarprepend
|
|
||||||
|
|
||||||
pathvarappend () {
|
|
||||||
# appending paths to pathvar denoted by the expansion of the PATHVAR parameter
|
|
||||||
# if it's already in the PATH, move it to the end
|
|
||||||
# POSIX compliant version
|
|
||||||
|
|
||||||
test -n "${2}" ||
|
|
||||||
{ echo "Usage: pathappend PATHVAR PATH_TO_ADD [PATH_TO_ADD...]";
|
|
||||||
echo "Example: pathappend LD_LIBRARY_PATH '${HOME}/.local/lib' '/usr/local/lib'";
|
|
||||||
return 2; }
|
|
||||||
|
|
||||||
pathvar="${1}"
|
|
||||||
|
|
||||||
case "${pathvar}" in (*[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_]*|""|[0123456789]*) false;; esac ||
|
|
||||||
{ echo 'Expanded pathvar is not a valid name/variable identifier'; return 3; }
|
|
||||||
|
|
||||||
if [ "${pathvar}" = "PATH" ]; then
|
|
||||||
test "${-#*r}" = "${-}" ||
|
|
||||||
{ echo 'Restricted shell, cannot change PATH'; return 4; }
|
|
||||||
fi
|
|
||||||
|
|
||||||
path_append_error="0"
|
|
||||||
|
|
||||||
while shift; [ "${#}" -gt "0" ]; do
|
|
||||||
norm_path_to_add="${1}"
|
|
||||||
|
|
||||||
test "${norm_path_to_add#*:}" = "${norm_path_to_add}" ||
|
|
||||||
{ echo 'Cannot add path with colon'; path_append_error="1"; continue; }
|
|
||||||
|
|
||||||
test -d "${norm_path_to_add}" ||
|
|
||||||
{ echo "path_to_add ('${norm_path_to_add}') not a directory"; path_append_error="1"; continue; }
|
|
||||||
|
|
||||||
norm_path="$(printf %s ":$(eval "printf %s "'"'"\$${pathvar}"'"'):" | head -n 1 | sed 's|/\+|/|g; s/\/$//; s/:/::/g')" # fence with colons, ensure one line, deduplicate slashes, trim trailing, duplicate colons
|
|
||||||
norm_path_to_add="$(printf %s "${norm_path_to_add}" | head -n 1 | sed 's|/\+|/|g; s/\/$//')" # ensure one line, deduplicate slashes, trim trailing
|
|
||||||
exec 3<<- 'EOF'
|
|
||||||
# escape BRE meta-characters
|
|
||||||
s/\\/\\./g # backslash first
|
|
||||||
s/\./\\./g
|
|
||||||
s/\^/\\^/g
|
|
||||||
s/\$/\\$/g
|
|
||||||
s/\*/\\*/g
|
|
||||||
s/\[/\\[/g
|
|
||||||
s|/|\\/|g # escape delimiter for outer sed
|
|
||||||
EOF
|
|
||||||
norm_path="$(printf %s "${norm_path}" | sed "s/:$(printf %s "${norm_path_to_add}" | sed -f /proc/self/fd/3 3<&3)://g")" # remove all instances of PATH_TO_ADD from PATH
|
|
||||||
exec 3<&-
|
|
||||||
norm_path="$(printf %s "${norm_path}" | sed 's/:\+/:/g; s/^://; s/:$//')" # deduplicate colons, trim leading and trailing
|
|
||||||
eval "${pathvar}=\${norm_path:+\$norm_path:}\$norm_path_to_add" # append with colon
|
|
||||||
done
|
|
||||||
return "${path_append_error}"
|
|
||||||
} && export -f pathvarappend
|
|
||||||
|
|
||||||
path_append () {
|
|
||||||
pathvarappend PATH "$@"
|
|
||||||
} && export -f path_append
|
|
||||||
|
|
||||||
ld_lib_path_append () {
|
|
||||||
pathvarappend LD_LIBRARY_PATH "$@"
|
|
||||||
} && export -f ld_lib_path_append
|
|
||||||
|
|
||||||
cdpath_append () {
|
|
||||||
pathvarappend CDPATH "$@"
|
|
||||||
} && export -f cdpath_append
|
|
||||||
|
|
||||||
path_prepend () {
|
|
||||||
pathvarprepend PATH "$@"
|
|
||||||
} && export -f path_prepend
|
|
||||||
|
|
||||||
ld_lib_path_prepend () {
|
|
||||||
pathvarprepend LD_LIBRARY_PATH "$@"
|
|
||||||
} && export -f ld_lib_path_prepend
|
|
||||||
|
|
||||||
cdpath_prepend () {
|
|
||||||
pathvarprepend CDPATH "$@"
|
|
||||||
} && export -f cdpath_prepend
|
|
||||||
|
|
||||||
# ld_lib_path_append \
|
|
||||||
# "${HOME}/.local/lib"
|
|
||||||
|
|
||||||
path_prepend \
|
|
||||||
"/bin" \
|
|
||||||
"/sbin" \
|
|
||||||
"/usr/bin" \
|
|
||||||
"/usr/sbin" \
|
|
||||||
"/usr/local/bin" \
|
|
||||||
"/usr/local/sbin" \
|
|
||||||
"/usr/games" \
|
|
||||||
"/usr/local/games" \
|
|
||||||
"/snap/bin" \
|
|
||||||
|
|
||||||
path_append \
|
|
||||||
"${HOME}/bin" \
|
|
||||||
"${HOME}/.bin" \
|
|
||||||
"${HOME}/.local/bin" \
|
|
||||||
"${HOME}/.local/sbin" \
|
|
||||||
"${HOME}/.brew/bin" \
|
|
||||||
"${GOPATH}/bin"
|
|
||||||
|
|
||||||
# add cargo bin to path
|
|
||||||
if [ -f "${HOME}/.cargo/env" ] && [ -r "${HOME}/.cargo/env" ]; then
|
|
||||||
. "${HOME}/.cargo/env"
|
|
||||||
fi
|
|
||||||
|
|
||||||
export NVM_DIR="${HOME}/.nvm"
|
|
||||||
[ -s "${NVM_DIR}/nvm.sh" ] && . "${NVM_DIR}/nvm.sh"
|
|
||||||
[ -s "${NVM_DIR}/bash_completion" ] && . "${NVM_DIR}/bash_completion"
|
|
||||||
|
|
||||||
1>/dev/null pidof -q startx && 1>/home/tosuman/.startx.log 2>&1 startx
|
1>/dev/null pidof -q startx && 1>/home/tosuman/.startx.log 2>&1 startx
|
||||||
|
|
||||||
# if running bash
|
# if running bash
|
||||||
[ -n "${BASH_VERSINFO}" ] && if [ -f "${HOME}/.bashrc" ] && [ -r "${HOME}/.bashrc" ] && . "${HOME}/.bashrc"
|
[ -n "$BASH_VERSINFO" ] && if [ -f "$HOME/.bashrc" ] && [ -r "$HOME/.bashrc" ] && . "$HOME/.bashrc"
|
||||||
|
|
Loading…
Reference in New Issue