[misc] refactory

This commit is contained in:
Klesh Wong 2020-11-09 00:26:14 +08:00
parent d1263edd4e
commit 7b160826f6
46 changed files with 227 additions and 245 deletions

2
.gitignore vendored
View File

@ -11,3 +11,5 @@ Thunar/config/accels.scm
nvim/config/autoload
nvim/config/plugged
nvim/config/.*
repos/
repo/

View File

@ -1 +1,12 @@
TODO
# dotfiles
* openurl copy move to dmenu
* auto install dict.sh
# How to use
1. fork this repo
2. run installation script base on your need
3. customize to your taste and sync to your own repo

2
apps/docker-arm.sh Executable file → Normal file
View File

@ -1,7 +1,7 @@
#!/bin/sh
set -e
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"

2
apps/docker.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"

2
apps/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"

2
apps/k8s.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"

2
apps/keepassxc.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"

2
apps/nextcloud.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"

2
autologin/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
echo 'Please enter autologin username (empty to skip): '

0
bak/config/polybar/launch.sh Executable file → Normal file
View File

0
bak/config/sxhkd/launch.sh Executable file → Normal file
View File

40
bin/br
View File

@ -1,21 +1,25 @@
#!/bin/sh
if [ "$#" -lt 2 ]; then
echo "Usage: $0 <target> <replacement>"
exit 1
# rule 1: use single quote '
# rule 2: //// for literal /
set -e
FILES=$(awk '{print}')
COL=$(tput cols)
PAT=$1
STR=$2
export COL PAT STR
echo "$FILES" | while IFS= read -r FILE; do
bin/fr "$FILE"
done | less
printf "Are you sure [y/N]? "
read -r YN < /dev/tty
if [ "$YN" = 'y' ]; then
echo "$FILES" | while IFS= read -r FILE; do
TMP=$(mktemp)
REP=1 bin/fr "$FILE" > "$TMP"
mv "$TMP" "$FILE"
done
fi
REDFG=$(printf '\033[31m')
BLUBG=$(printf '\033[42m')
ag --color "$1" . | sed -E "s/$1/\\0$REDFG$BLUBG$2/g"
echo Are they ok for you?
read -r YN
case "$YN" in
y|Y)
ag "$1" . -l -0 | xargs -0 sed -Ei "s/$1/$2/g"
;;
*)
exit
;;
esac

74
bin/fr Executable file
View File

@ -0,0 +1,74 @@
#!/bin/gawk -f
BEGIN {
PAT = "(" ENVIRON["PAT"] ")"
STR = ENVIRON["STR"]
REP = ENVIRON["REP"]
COL = ENVIRON["COL"]
OLD = "\033[31m"
NEW = "\033[32m"
LNN = "\033[30m\033[47m"
LNH = "\033[30m\033[41m"
RST = "\033[0m"
CTX = 2
#print "PAT:" PAT
#print "STR:" STR
}
function min(a, b) {
return a > b ? b : a
}
function fileend() {
if (REP) exit
split(buffer, lines, "\n")
if (!length(lines)) exit
printf "\033[42m\033[30m%s%" COL-length(filename) "s\033[0m\n", filename, " "
pad = length(length(lines) - 1)
for (i in lines) {
if (!match(lines[i], /([[:digit:]]+)(:|-)(.*)$/, m))
continue
linno = m[1]
found = m[2] == ":"
line = m[3]
print (found ? LNH : LNN) sprintf(" %"pad"d ", linno) RST line
}
}
!REP && FNR == 1 {
if (buffer) fileend()
filename = FILENAME
delete before
buffer = ""
printed = 0
}
!REP {
delete data
line = gensub(PAT, OLD "\\1" NEW STR RST, "g", $0)
found = index(line, OLD)
fmted = FNR (found ? ":" : "-") line
if (found) {
for (i = min(FNR-printed-1, CTX); i > 0; i--) {
if (before[i]) buffer = buffer "\n" before[i]
}
buffer = buffer "\n" fmted
printed = FNR
keep = CTX
} else if (keep-- > 0) {
buffer = buffer "\n" fmted
printed = FNR
}
for (i = CTX; i > 1; i--) {
before[i] = before[i - 1]
}
before[1] = fmted
}
END { fileend() }
REP {
print gensub(PAT, STR, "g", $0)
}

2
deeplearning/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"

View File

@ -1,7 +1,5 @@
#!/bin/sh
DIR=$(readlink -f $(dirname $0))
killall -q dunst
while pgrep -x dunst >/dev/null; do sleep 1; done
dunst -config $DIR/dunstrc &
dunst &

7
dunst/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# install nvim
@ -14,5 +14,6 @@ case "$PM" in
esac
# symlink configuration
lnsf "$DIR/config/dunstrc" "$XDG_CONFIG_HOME/dunst/dunstrc"
lnsf "$DIR/config/launch.sh" "$XDG_CONFIG_HOME/dunst/launch.sh"
lnsf "$DIR/content/dunstrc" "$XDG_CONFIG_HOME/dunst/dunstrc"
sudo cp -f "$DIR/content/dunstctl" "$PREFIX/bin"
sudo chmod +x "$PREFIX/bin/dunstctl"

23
env.sh Executable file → Normal file
View File

@ -3,9 +3,14 @@
set -e
PM=n/a
XDG_CONFIG_HOME=${XDG_CONFIG_HOME-"$HOME/.config"}
PREFIX=/usr/local
PDIR=$(dirname "${DIR-$0}")
GITHUB_PROXY=${GITHUB_PROXY-$HTTPS_PROXY}
echo "dir: $DIR"
echo "parent dir: $PDIR"
echo "prefix dir: $PREFIX"
sudo mkdir -p $PREFIX
if command -v pacman > /dev/null; then
PM=pacman
@ -31,7 +36,7 @@ in_china () {
lnsf () {
[ "$#" -ne 2 ] && echo "lnsf <target> <symlink>" && return 1
TARGET=$(readlink -f "$1")
TARGET=$(readlink -f "$1") || echo failed: readlink -f "$1" && return 1
SYMLNK=$2
[ -z "$TARGET" ] && echo "$1 not exists" && return 1
SYMDIR=$(dirname "$SYMLNK")
@ -55,6 +60,22 @@ eqv () {
[ "$VERSION" = "$VERSION2" ]
}
intorepo() {
ODIR=$(pwd)
REPO=$2
if [ ! -d "$REPO" ]; then
HTTPS_PROXY=$GITHUB_PROXY git clone --depth 1 "$1" "$REPO"
cd "$REPO"
else
cd "$REPO"
git pull
fi
}
exitrepo() {
cd "$ODIR"
}
# install basic common utilities
case "$PM" in

2
fish/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# install fish shell

0
gui/freetype2.sh Executable file → Normal file
View File

2
gui/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# install basic gui stuff, including fonts/system utilties/keyring etc

2
gui/sshd.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# install sshd

2
gui/theme.sh Executable file → Normal file
View File

@ -1,7 +1,7 @@
#!/bin/sh
set -e
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# for better looking

2
gui/updatenerdfonticons.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
[ -z "$1" ] && echo Usage: $0 path/to/nerdfont.git/bin/scrips/lib && exit 1

2
kvm/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# tips

2
nodejs/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# install specific version

2
nvim/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# check dependencies

0
optim/bbr.sh Executable file → Normal file
View File

2
optim/mirrors.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"

0
optim/ubuntu-desk-boot.sh Executable file → Normal file
View File

View File

@ -1,11 +0,0 @@
#!/bin/sh
DIR=$(readlink -f $(dirname $0))
killall -q picom
while pgrep -x picom >/dev/null; do sleep 1; done
picom -b --config $DIR/picom.conf --experimental-backends \
--blur-method dual_kawase --blur-strength 6 \
--no-fading-openclose
sleep 1
! pgrep -x picom && picom -b --config $DIR/picom.conf --no-fading-openclose

View File

@ -1,9 +0,0 @@
#!/bin/sh
DIR=$(readlink -f $(dirname $0))
if pgrep -x picom > /dev/null; then
killall -q picom
else
$DIR/launch.sh
fi

36
picom/content/picomdaemon Executable file
View File

@ -0,0 +1,36 @@
#!/bin/sh
set -e
stop() {
echo stop
killall -q picom || true
while pgrep -x picom >/dev/null; do sleep 1; done
}
start() {
echo start
picom -b --experimental-backends \
--blur-method dual_kawase --blur-strength 6 \
--no-fading-openclose
sleep 1
! pgrep -x picom >/dev/null && echo 'fallback' && picom -b --no-fading-openclose
}
toggle() {
if pgrep -x picom > /dev/null; then
stop
else
start
fi
}
case $1 in
toggle)
toggle
;;
*)
stop
start
;;
esac

31
picom/install.sh Executable file → Normal file
View File

@ -1,11 +1,11 @@
#!/bin/sh
set -e
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# install ranger
# install dpes
case "$PM" in
apt)
# install build tools
@ -20,24 +20,13 @@ case "$PM" in
esac
# build and install picom
VERSION=next
VERSION_PATH=$XDG_CONFIG_HOME/picom/version
if [ "$VERSION" = "next" ] || ! eqv "$VERSION_PATH" "$VERSION"; then
echo Downloading picom $VERSION
[ ! -f /tmp/picom-$VERSION.zip ] && \
curl "https://github.com/yshui/picom/archive/$VERSION.zip" -Lo /tmp/picom-$VERSION.zip
unzip /tmp/picom-$VERSION.zip -d /tmp
FD=$(unzip -l /tmp/picom-$VERSION.zip | awk 'NR==5{print $4}')
cd "/tmp/$FD"
meson --buildtype=release . build
sudo ninja -C build install
cd -
mkdir -p "$(dirname "$VERSION_PATH")"
echo "$VERSION" > "$VERSION_PATH"
sudo rm -rf /tmp/picom-$VERSION*
fi
intorepo https://github.com/yshui/picom.git "$DIR/repo"
meson --buildtype=release . build
sudo ninja -C build install
exitrepo
sudo cp -f "$DIR/content/picomdaemon" "$PREFIX/bin"
sudo chmod +x "$PREFIX/bin/picomdaemon"
echo 'picom installed'
# configuration
lnsf "$DIR/config/launch.sh" "$XDG_CONFIG_HOME/picom/launch.sh"
lnsf "$DIR/config/toggle.sh" "$XDG_CONFIG_HOME/picom/toggle.sh"
lnsf "$DIR/config/picom.conf" "$XDG_CONFIG_HOME/picom/picom.conf"
lnsf "$DIR/content/picom.conf" "$XDG_CONFIG_HOME/picom/picom.conf"

2
player/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"

2
python/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# config pip mirror for CHINA

0
python/py3.sh Executable file → Normal file
View File

0
ranger/config/scope.sh Executable file → Normal file
View File

2
ranger/install.sh Executable file → Normal file
View File

@ -1,7 +1,7 @@
#!/bin/sh
set -e
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# install ranger

View File

@ -1,13 +1,13 @@
#!/bin/sh
# start compositor daemon
"$HOME/.config/picom/launch.sh"
picomdaemon
# start desktop notification daemon
"$HOME/.config/dunst/launch.sh"
dunstdaemon
# start dwmbar daemon
"$HOME/.config/dwm/statusbar"
statusbar
# disable screen saver / turn off monitor if inactived for 300 secs
xset s off

View File

@ -1,135 +0,0 @@
#!/bin/sh
# symbola
#export ICON_RCD=🎥
#export ICON_MSC=♬
#export ICON_MTD=🔉
#export ICON_VOL=🔊
#export ICON_NIC=🖧
#export ICON_WFI=📡
#export ICON_MEM=📈
#export ICON_TMP=🌡
#export ICON_PLG=🔌
#export ICON_BAT=🔋
#export ICON_DAT=⏲
# nerdfont
export ICON_RCD='辶'
export ICON_MSC=''
export ICON_MTD='ﱝ '
export ICON_VOL=' '
export ICON_NIC=' '
export ICON_WFI=' '
export ICON_MEM=' '
export ICON_TMP=''
export ICON_PLG=' '
export ICON_BA0=' '
export ICON_BA1=' '
export ICON_BA2=' '
export ICON_BA3=' '
export ICON_BA4=' '
export ICON_DAT=' '
MPD=$(which mpc && echo yes)
statusbar() {
echo -n " "
# recording
[ -f /tmp/recording.pid ] && echo -n "$ICON_RCD "
# mpd
[ -n "$MPD" ] && mpc | awk '
NR == 1 {
SONG = $0
}
NR == 2 {
PLAYING = $1
}
END {
if (PLAYING == "[playing]")
printf "%s %s ", ENVIRON["ICON_MSC"], SONG
}
'
# volume
amixer get Master | awk 'END {
ICO = $NF == "[off]" ? ENVIRON["ICON_MTD"] : ENVIRON["ICON_VOL"]
match($0, / \[([0-9]+%)\] /, m)
VOL = m[1]
printf "%s %s ", ICO, VOL
}'
# network
for NIC in /sys/class/net/e*; do
grep -q 'up' $NIC/operstate && awk '{
printf "%s %s ",ENVIRON["ICON_NIC"],($0 >= 1000 ? $0 / 1000 "G" : $0 "M")
}' $NIC/speed
done
# wifi
awk 'NR > 2 {
printf "%s %i%% ", ENVIRON["ICON_WFI"], $3*100/70
}' /proc/net/wireless
# cpu temperature
awk '{
printf "%s %i°C ", ENVIRON["ICON_TMP"], $0/1000
}' /sys/class/thermal/thermal_zone0/temp
# memory usage
free | awk 'NR == 2 {
printf "%s %i%% ", ENVIRON["ICON_MEM"], $3/$2*100
}'
# battery
if [ -f /sys/class/power_supply/BAT0/capacity ]; then
grep -q '1' /sys/class/power_supply/AC/online && export PLUGGED=yes
awk '{
if (ENVIRON["PLUGGED"] == "yes")
ICON=ENVIRON["ICON_PLG"]
else if ($0 > 90)
ICON=ENVIRON["ICON_BA4"]
else if ($0 > 75)
ICON=ENVIRON["ICON_BA3"]
else if ($0 > 50)
ICON=ENVIRON["ICON_BA2"]
else if ($0 > 25)
ICON=ENVIRON["ICON_BA1"]
else
ICON=ENVIRON["ICON_BA0"]
printf "%s %s%% ", ICON, $0
}' /sys/class/power_supply/BAT0/capacity
fi
# datetime
echo -n "$ICON_DAT $(date +'%m-%d %H:%M %a') "
}
start() {
while :; do
! pgrep slock 1>/dev/null && xsetroot -name "$(statusbar)"
sleep 1
done
}
restart() {
FP=$(readlink -f $0)
pkill -f "$FP loop"
$FP loop &
}
case "$1" in
loop)
start
;;
dryrun)
statusbar
;;
*)
restart
;;
esac

37
suckless/install.sh Executable file → Normal file
View File

@ -1,6 +1,7 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
set -e
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
"$PDIR/fish/install.sh"
@ -36,19 +37,23 @@ case "$PM" in
esac
# clone / compile utilities and dwm itself
mkdir -p ~/Projects/suckless
REPOS="$DIR/suckless/repos"
mkdir -p "$REPOS"
[ ! -d ~/Projects/suckless/st ] && git clone https://gitee.com/klesh/st.git ~/Projects/suckless/st
cd ~/Projects/suckless/st && sudo rm -f config.h && sudo make clean install
installrepo () {
ODIR=$(pwd)
REPO="$DIR/suckless/repos/$2"
[ ! -d "$REPO" ] && git clone --depth "$1" "$REPO"
cd "$REPO"
make && sudo make install
cd "$ODIR"
}
[ ! -d ~/Projects/suckless/dmenu ] &&git clone https://gitee.com/klesh/dmenu.git ~/Projects/suckless/dmenu
cd ~/Projects/suckless/dmenu && sudo rm -f config.h && sudo make clean install
[ ! -d ~/Projects/suckless/slock ] &&git clone https://gitee.com/klesh/slock.git ~/Projects/suckless/slock
cd ~/Projects/suckless/slock && sudo rm -f config.h && sudo make clean install
[ ! -d ~/Projects/suckless/dwm ] &&git clone https://gitee.com/klesh/dwm.git ~/Projects/suckless/dwm
cd ~/Projects/suckless/dwm && sudo rm -f config.h && sudo make clean install
installrepo https://gitee.com/klesh/st.git st
installrepo https://gitee.com/klesh/dmenu.git dmenu
installrepo https://gitee.com/klesh/slock.git slock
installrepo https://github.com/klesh/dict.sh.git dict.sh
installrepo https://gitee.com/klesh/dwm.git dwm
# config xinit to start for dwm
rm ~/.xinitrc
@ -70,14 +75,10 @@ export SSH_AUTH_SOCK=$(/usr/bin/gnome-keyring-daemon --start --components=pkcs11
autorandr --change --force
# restart dwm if it existed without error
echo $$(date "+%Y%m%d-%H%M%S") '=============== xrdb -query' >> /tmp/xinit.log
xrdb -query >> /tmp/dwm.log
echo $$(date "+%Y%m%d-%H%M%S") '=============== enter dwm' >> /tmp/xinit.log
xrdb -query > /tmp/dwm.log
while :; do
ssh-agent dwm 2>>/tmp/dwm.log || break
echo $$(date "+%Y%m%d-%H%M%S") '=============== restart dwm' >> /tmp/xinit.log
done
echo $$(date "+%Y%m%d-%H%M%S") '=============== exit xinit' >> /tmp/xinit.log
EOT
cat <<'EOT' > ~/.profile
@ -85,6 +86,7 @@ cat <<'EOT' > ~/.profile
export PATH=$HOME/dotfiles/bin:$HOME/.local/bin:$PATH
export VIM_MODE=enhanced
export DMENU_DEFAULT_OPTS='-i -c -fn monospace:13 -nb #222222 -nf #bbbbbb -sb #5b97f7 -sf #eeeeee -l 20'
# auto startx
[ -z "$DISPLAY" ] && [ -n "$XDG_VTNR" ] && [ "$XDG_VTNR" -eq "1" ] \
@ -97,5 +99,4 @@ EOT
[ -L "$XDG_CONFIG_HOME/dwm/autostart" ] && rm "$XDG_CONFIG_HOME/dwm/autostart"
mkdir -p "$XDG_CONFIG_HOME/dwm"
cp "$DIR/config/dwm/autostart" "$XDG_CONFIG_HOME/dwm/autostart"
lnsf "$DIR/config/dwm/statusbar" "$XDG_CONFIG_HOME/dwm/statusbar"
lnsf "$DIR/config/autorandr/postswitch" "$XDG_CONFIG_HOME/autorandr/postswitch"

2
thunar/install.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
# install ranger

2
tmux/install.sh Executable file → Normal file
View File

@ -1,7 +1,7 @@
#!/bin/sh
set -e
DIR=$(readlink -f "$(dirname "$0")")
DIR=$(dirname "$(readlink -f "$0")")
. "$DIR/../env.sh"
TMUX_VER=3.1b

0
win/wsl.sh Executable file → Normal file
View File