From 39b8219a266998cd03341590d6aacd0d452f772f Mon Sep 17 00:00:00 2001 From: Klesh Wong Date: Sat, 19 Sep 2020 23:33:13 +0800 Subject: [PATCH] [bugfix] fix some symlink issues --- apps/install.sh | 2 +- bak/config/polybar/launch.sh | 0 bak/config/sxhkd/launch.sh | 0 deeplearning/install.sh | 6 ++++-- dunst/config/config | 1 - dunst/install.sh | 3 ++- env.sh | 27 ++++++++++++++++++++------- fish/config/config.fish | 4 +++- fish/install.sh | 11 +++++------ gui/install.sh | 4 ++-- gui/theme.sh | 4 ++-- nvim/install.sh | 2 +- picom/config/config | 1 - picom/install.sh | 27 ++++++++++++++++++--------- player/install.sh | 10 +++++----- postswitch | 1 + ranger/install.sh | 4 ++-- suckless/config/autorandr/postswitch | 24 ++++++++++++++++++++++++ suckless/config/config | 1 - suckless/config/{ => dwm}/autostart | 0 suckless/config/{ => dwm}/dwmbar | 0 suckless/install.sh | 8 +++++--- suckless/postswitch | 23 ----------------------- thunar/install.sh | 2 +- tmux/install.sh | 2 +- 25 files changed, 97 insertions(+), 70 deletions(-) mode change 100644 => 100755 bak/config/polybar/launch.sh mode change 100644 => 100755 bak/config/sxhkd/launch.sh delete mode 120000 dunst/config/config delete mode 120000 picom/config/config create mode 120000 postswitch create mode 100755 suckless/config/autorandr/postswitch delete mode 120000 suckless/config/config rename suckless/config/{ => dwm}/autostart (100%) rename suckless/config/{ => dwm}/dwmbar (100%) delete mode 100644 suckless/postswitch diff --git a/apps/install.sh b/apps/install.sh index 89353e6..60cfffe 100755 --- a/apps/install.sh +++ b/apps/install.sh @@ -25,4 +25,4 @@ case "$PM" in esac # symlink configuration -lnsf $DIR/config/zathura ~/.config/zathura +lnsf $DIR/config/zathura $XDG_CONFIG_HOME/zathura diff --git a/bak/config/polybar/launch.sh b/bak/config/polybar/launch.sh old mode 100644 new mode 100755 diff --git a/bak/config/sxhkd/launch.sh b/bak/config/sxhkd/launch.sh old mode 100644 new mode 100755 diff --git a/deeplearning/install.sh b/deeplearning/install.sh index 4896633..424e15b 100755 --- a/deeplearning/install.sh +++ b/deeplearning/install.sh @@ -16,7 +16,8 @@ case "$PM" in if [ "$DISTRIB_RELEASE" = "18.04" ] && [ "$(uname -m)" = 'x86_64' ]; then wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600 - sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub + sudo apt-key adv --fetch-keys \ + https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub sudo add-apt-repository "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /" sudo apt-get update sudo apt-get -y install cuda @@ -28,7 +29,8 @@ case "$PM" in fi distribution=$(. /etc/os-release;echo $ID$VERSION_ID) curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - - curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list + curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | \ + sudo tee /etc/apt/sources.list.d/nvidia-docker.list sudo apt update sudo apt install -y nvidia-docker2 ;; diff --git a/dunst/config/config b/dunst/config/config deleted file mode 120000 index 593f4c5..0000000 --- a/dunst/config/config +++ /dev/null @@ -1 +0,0 @@ -/home/klesh/dotfiles/dunst/config \ No newline at end of file diff --git a/dunst/install.sh b/dunst/install.sh index 04689aa..fc672b1 100755 --- a/dunst/install.sh +++ b/dunst/install.sh @@ -14,4 +14,5 @@ case "$PM" in esac # symlink configuration -lnsf $DIR/config ~/.config/dunst +lnsf $DIR/config/dunstrc $XDG_CONFIG_HOME/dunst/dunstrc +lnsf $DIR/config/launch.sh $XDG_CONFIG_HOME/dunst/launch.sh diff --git a/env.sh b/env.sh index 13f0581..2bd1f7b 100755 --- a/env.sh +++ b/env.sh @@ -5,6 +5,7 @@ ROOT=$(readlink -f $(dirname "${BASH_SOURCE[0]}")) PM=n/a DEFAULT_SHELL=$(getent passwd $USER | cut -d: -f7) FISH=$(which fish) +XDG_CONFIG_HOME=${XDG_CONFIG_HOME-"$HOME/.config"} if which pacman > /dev/null; then PM=pacman @@ -29,14 +30,17 @@ in-china () { } lnsf () { - [ "$#" -ne 2 ] && echo "lnsf " - [ ! -L "$2" ] && rm -rf $2 - SYM_DIR=$(dirname $2) - if [ -n "$SYM_DIR" ]; then - [ ! -d "$SYM_DIR" ] && rm -rf "$SYM_DIR" - mkdir -p "$SYM_DIR" + [ "$#" -ne 2 ] && echo "lnsf " && return -1 + local TARGET=$(readlink -f $1) + local SYMLNK=$2 + [ -z "$TARGET" ] && echo "$1 not exists" && return -1 + local SYMDIR=$(dirname $SYMLNK) + if [ -n "$SYMDIR" ] && [ -L $SYMDIR ]; then + rm -rf $SYMDIR + mkdir -p $SYMDIR fi - ln -sf $1 $2 + [ ! -L $SYMLNK ] && rm -rf $SYMLNK + ln -sf $TARGET $SYMLNK } fish-is-default-shell () { @@ -47,6 +51,14 @@ has-bluetooth () { dmesg | grep -i bluetooth } +eqv () { + local VERSION_PATH=$1 + local VERSION=$2 + [ ! -f $VERSION_PATH ] && return -1 + local VERSION2=$(cat "$VERSION_PATH") + [ "$VERSION" = "$VERSION2" ] +} + # install basic common utilities case "$PM" in @@ -69,3 +81,4 @@ case "$PM" in man sudo ;; esac + diff --git a/fish/config/config.fish b/fish/config/config.fish index 8a756fb..2853e8d 100644 --- a/fish/config/config.fish +++ b/fish/config/config.fish @@ -1,4 +1,6 @@ -set -gx EDITOR vim +#!/usr/bin/env fish + +set -gx EDITOR nvim set -gx PGDATA /usr/local/var/postgres set -gx LESS "-SRXF" set -gx LS_COLORS 'ow=34;42;40' diff --git a/fish/install.sh b/fish/install.sh index bec9838..97ae8d1 100755 --- a/fish/install.sh +++ b/fish/install.sh @@ -24,11 +24,10 @@ if ! fish-is-default-shell; then fi # symlink config -[ -L ~/.config/fish ] && rm -rf ~/.config/fish +[ -L $XDG_CONFIG_HOME/fish ] && rm -rf $XDG_CONFIG_HOME/fish -lnsf $DIR/config/config.fish ~/.config/fish/config.fish -lnsf $DIR/config/functions/fish_prompt.fish ~/.config/fish/functions/fish_prompt.fish -lnsf $DIR/config/functions/fish_right_prompt.fish ~/.config/fish/functions/fish_right_prompt.fish -lnsf $DIR/config/functions/fisher.fish ~/.config/fish/functions/fisher.fish +lnsf $DIR/config/config.fish $XDG_CONFIG_HOME/fish/config.fish +lnsf $DIR/config/functions/fish_prompt.fish $XDG_CONFIG_HOME/fish/functions/fish_prompt.fish +lnsf $DIR/config/functions/fish_right_prompt.fish $XDG_CONFIG_HOME/fish/functions/fish_right_prompt.fish +lnsf $DIR/config/functions/fisher.fish $XDG_CONFIG_HOME/fish/functions/fisher.fish -source ~/.config/fish/config.fish diff --git a/gui/install.sh b/gui/install.sh index 84c531b..1a52131 100755 --- a/gui/install.sh +++ b/gui/install.sh @@ -11,7 +11,7 @@ case "$PM" in fonts-cascadia-code \ ttf-dejavu \ fonts-urw-base35 \ - fonts-noto-cjk \ + fonts-wqy-microhei \ gucharmap # network manager sudo apt install \ @@ -31,7 +31,7 @@ case "$PM" in freetype2 \ ttf-cascadia-code \ ttf-dejavu \ - noto-fonts-cjk \ + wqy-microhei \ gucharmap # clipboard sudo pacman -S --needed \ diff --git a/gui/theme.sh b/gui/theme.sh index e48b670..1c73d12 100755 --- a/gui/theme.sh +++ b/gui/theme.sh @@ -16,5 +16,5 @@ case "$PM" in esac # configuration -lnsf $DIR/config/gtk-3.0/settings.ini ~/.config/gtk-3.0/settings.ini -lnsf $DIR/config/qt5ct/qt5ct.conf ~/.config/qt5ct/qt5ct.conf +lnsf $DIR/config/gtk-3.0/settings.ini $XDG_CONFIG_HOME/gtk-3.0/settings.ini +lnsf $DIR/config/qt5ct/qt5ct.conf $XDG_CONFIG_HOME/qt5ct/qt5ct.conf diff --git a/nvim/install.sh b/nvim/install.sh index c8df40c..246dadc 100755 --- a/nvim/install.sh +++ b/nvim/install.sh @@ -19,5 +19,5 @@ case "$PM" in esac # symlink configuration -lnsf $DIR/config/init.vim ~/.config/nvim/init.vim +lnsf $DIR/config/init.vim $XDG_CONFIG_HOME/nvim/init.vim lnsf $DIR/config/init.vim ~/.vimrc diff --git a/picom/config/config b/picom/config/config deleted file mode 120000 index 2347e4b..0000000 --- a/picom/config/config +++ /dev/null @@ -1 +0,0 @@ -/home/klesh/dotfiles/picom/config \ No newline at end of file diff --git a/picom/install.sh b/picom/install.sh index be03c79..7e42011 100755 --- a/picom/install.sh +++ b/picom/install.sh @@ -20,14 +20,23 @@ case "$PM" in ;; esac -# build and install picom-next -curl 'https://github.com/yshui/picom/archive/next.zip' -sLo /tmp/picom-next.zip -unzip /tmp/picom-next.zip -d /tmp -pushd /tmp/picom-next -meson --buildtype=release . build -sudo ninja -C build install -popd -sudo rm -rf /tmp/picom* +# 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 + rm -rf /tmp/picom.zip + curl "https://github.com/yshui/picom/archive/$VERSION.zip" -Lo /tmp/picom-$VERSION.zip + unzip /tmp/picom-$VERSION.zip -d /tmp + pushd /tmp/picom-$VERSION + meson --buildtype=release . build + sudo ninja -C build install + popd + echo "$VERSION" > "$VERSION_PATH" + sudo rm -rf /tmp/picom-$VERSION* +fi # configuration -lnsf $DIR/config ~/.config/picom +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 diff --git a/player/install.sh b/player/install.sh index bf89516..8e288ea 100755 --- a/player/install.sh +++ b/player/install.sh @@ -14,11 +14,11 @@ case "$PM" in ;; esac +# symlink configuration +lnsf $DIR/config/mpd $XDG_CONFIG_HOME/mpd +lnsf $DIR/config/ncmpcpp $XDG_CONFIG_HOME/ncmpcpp +lnsf $DIR/config/mpv $XDG_CONFIG_HOME/mpv + # enable for current user systemctl --user enable mpd systemctl --user start mpd - -# symlink configuration -lnsf $DIR/config/mpd ~/.config/mpd -lnsf $DIR/config/ncmpcpp ~/.config/ncmpcpp -lnsf $DIR/config/mpv ~/.config/mpv diff --git a/postswitch b/postswitch new file mode 120000 index 0000000..8121bc9 --- /dev/null +++ b/postswitch @@ -0,0 +1 @@ +/home/klesh/.config/autorandr/postswitch \ No newline at end of file diff --git a/ranger/install.sh b/ranger/install.sh index c68e4b3..7fe32b1 100755 --- a/ranger/install.sh +++ b/ranger/install.sh @@ -10,8 +10,8 @@ case "$PM" in sudo pip3 install ranger-fm ueberzug ;; pacman) - sudo pacman -S --needed ranger ueberzug + sudo pip install ranger-fm ueberzug ;; esac -lnsf $DIR/config ~/.config/ranger +lnsf $DIR/config $XDG_CONFIG_HOME/ranger diff --git a/suckless/config/autorandr/postswitch b/suckless/config/autorandr/postswitch new file mode 100755 index 0000000..4846cb7 --- /dev/null +++ b/suckless/config/autorandr/postswitch @@ -0,0 +1,24 @@ +#!/bin/bash + +# set system dpi to the minimal dpi among all connected monitors + +MIN_DPI=99999999 + +# loop through all connected monitors line by line +while IFS= read -r LINE; do + WIDTH_PX=$(echo $LINE | grep -oP '\d+(?=x\d+)') + [ -z "$WIDTH_PX" ] && continue + WIDTH_MM=$(echo $LINE | grep -oP '\d+(?=mm x)') + # calculate dpi of the monitor + DPI=$(bc <<< "$WIDTH_PX*25.4/$WIDTH_MM") + # update min dpi + if [ "$DPI" -lt "$MIN_DPI" ]; then + MIN_DPI=$DPI + fi +done <<< "$(xrandr | grep ' connected')" + +# update dpi +echo setting dpi to $MIN_DPI +echo Xft.dpi: $MIN_DPI | xrdb -merge + +nitrogen --restore diff --git a/suckless/config/config b/suckless/config/config deleted file mode 120000 index 66a656d..0000000 --- a/suckless/config/config +++ /dev/null @@ -1 +0,0 @@ -/home/klesh/dotfiles/suckless/config \ No newline at end of file diff --git a/suckless/config/autostart b/suckless/config/dwm/autostart similarity index 100% rename from suckless/config/autostart rename to suckless/config/dwm/autostart diff --git a/suckless/config/dwmbar b/suckless/config/dwm/dwmbar similarity index 100% rename from suckless/config/dwmbar rename to suckless/config/dwm/dwmbar diff --git a/suckless/install.sh b/suckless/install.sh index e98c3fe..23bdfb4 100755 --- a/suckless/install.sh +++ b/suckless/install.sh @@ -32,7 +32,7 @@ case "$PM" in gnome-keyring \ xss-lock \ nitrogen \ - lm-sensors \ + i2c-tools \ trayer ;; esac @@ -80,10 +80,12 @@ export SSH_AUTH_SOCK autorandr --change --force while :; do - ssh-agent dwm 2>/tmp/dwm.log || break + ssh-agent dwm 2>/tmp/dwm.log || break done EOT # config dwm -lnsf $DIR/config ~/.config/dwm +lnsf $DIR/config/dwm/autostart $XDG_CONFIG_HOME/dwm/autostart +lnsf $DIR/config/dwm/dwmbar $XDG_CONFIG_HOME/dwm/dwmbar +lnsf $DIR/config/autorandr/postswitch $XDG_CONFIG_HOME/autorandr/postswitch diff --git a/suckless/postswitch b/suckless/postswitch deleted file mode 100644 index cfa9cf4..0000000 --- a/suckless/postswitch +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env fish - -set connecteds (xrandr | grep ' connected') -set total (count $monitors) -set dpis -set min_dpi 100000 - - -# set dpi to the lowest one -for connected in $connecteds - set name (echo $connected | awk -F' ' '{print $1}') - set x_res (echo $connected | grep -oP '\d+x\d+' | string split 'x' | head -n 1) - set x_wid (echo $connected | grep -oP '\d+mm' | head -n 1 | grep -oP '\d+') - set dpi (math -s0 "$x_res*25.4/$x_wid") - if test $dpi -lt $min_dpi - set min_dpi $dpi - end -end - -echo setting dpi to $min_dpi -echo Xft.dpi: $min_dpi | xrdb -merge - -nitrogen --restore diff --git a/thunar/install.sh b/thunar/install.sh index 3651db4..3011994 100755 --- a/thunar/install.sh +++ b/thunar/install.sh @@ -16,4 +16,4 @@ case "$PM" in esac # symlink configuration -lnsf $DIR/Thunar/uca.xml ~/.config/Thunar/uca.xml +lnsf $DIR/Thunar/uca.xml $XDG_CONFIG_HOME/Thunar/uca.xml diff --git a/tmux/install.sh b/tmux/install.sh index 52ce9b6..1575056 100755 --- a/tmux/install.sh +++ b/tmux/install.sh @@ -31,4 +31,4 @@ esac # symlink configuration lnsf $DIR/tmux.conf ~/.tmux.conf -lnsf $DIR/config ~/.config/tmux +lnsf $DIR/config $XDG_CONFIG_HOME/tmux