From 1212ef28b369a4c9e53c449bcb59fce8d2b12371 Mon Sep 17 00:00:00 2001 From: Yigit Colakoglu Date: Sat, 10 Apr 2021 14:50:46 +0300 Subject: [PATCH] Some scripts fixed up, support for dwm restart --- .config/X11/xinitrc | 16 ++++++++++------ .local/bin/dmenu-logout | 2 +- .local/bin/dmenu-refresh | 7 +------ .local/bin/status-bar/bluetooth | 2 +- .local/bin/status-bar/date | 2 +- .local/bin/status-bar/mpc | 6 +++--- .local/bin/status-bar/network | 14 +++++++++++++- .local/src/dwm/keybind.h | 10 ++++++---- .local/src/dwm/patches.h | 2 +- .profile | 3 +-- 10 files changed, 38 insertions(+), 26 deletions(-) diff --git a/.config/X11/xinitrc b/.config/X11/xinitrc index 0151b2c3..120a0bad 100755 --- a/.config/X11/xinitrc +++ b/.config/X11/xinitrc @@ -9,6 +9,7 @@ pkill -f devmon echo "$DBUS_SESSION_BUS_ADDRESS" > /tmp/bus-session rm -rf $XDG_RUNTIME_DIR/day_cache +export XSESSION_PID="$$" source ~/.config/config.env gpgconf --dry-run --create-socketdir @@ -70,14 +71,17 @@ redshift -x 2> /dev/null > /dev/null redshift -r -l "$LATLONG" > /dev/null 2> /dev/null & tmux new-session -s weechat -d weechat > /dev/null 2> /dev/null - -touch ~/.cache/dwm-restart -while [ -f /home/yigit/.cache/dwm-restart ]; +restarted=0 +while true; do - rm -rf /home/yigit/.cache/dwm-restart + if [ $restarted = 0 ]; then + restarted=1 + else + notify-send -a " Desktop Manager" "Dwm Restarted" + fi + dwmblocks > $XDG_RUNTIME_DIR/dwmblocks.out 2> $XDG_RUNTIME_DIR/dwmblocks.err & - exec dwm > $XDG_RUNTIME_DIR/dwm.log 2> $XDG_RUNTIME_DIR/dwm.err - sleep 0.2 + dwm > $XDG_RUNTIME_DIR/dwm.log 2> $XDG_RUNTIME_DIR/dwm.err done firefox-sync diff --git a/.local/bin/dmenu-logout b/.local/bin/dmenu-logout index 1de59040..aebe6031 100755 --- a/.local/bin/dmenu-logout +++ b/.local/bin/dmenu-logout @@ -35,7 +35,7 @@ selection=$(printf '%s' "$items" | $DMENU) case $selection in logout) - logout + kill -9 "$XSESSION_PID" ;; hibernate) loginctl hibernate diff --git a/.local/bin/dmenu-refresh b/.local/bin/dmenu-refresh index 5e90e070..3e49a5dc 100755 --- a/.local/bin/dmenu-refresh +++ b/.local/bin/dmenu-refresh @@ -7,10 +7,6 @@ killprogs() { pkill -x redshift } -logout() { - pkill dwm -} - DMENU='dmenu -z 1900 -x 10 -y 10 -i' items="dwm @@ -28,8 +24,7 @@ selection=$(printf '%s' "$items" | $DMENU) case $selection in dwm) - touch /home/yigit/.cache/dwm-restart - logout + kill -9 $(pidof dwm) ;; dwmblocks) kill -9 $(pidof dwmblocks) diff --git a/.local/bin/status-bar/bluetooth b/.local/bin/status-bar/bluetooth index 0056eb2e..6e8fe462 100755 --- a/.local/bin/status-bar/bluetooth +++ b/.local/bin/status-bar/bluetooth @@ -5,7 +5,7 @@ power=$(timeout 1 bluetoothctl show | grep "Powered: yes" | wc -w) if [ "$power" -eq 0 ]; then echo "^c#81a1c1^^d^" # Add color else - device="$(echo info | bluetoothctl | grep 'Name')" + device="$(echo info | timeout 1 bluetoothctl | grep 'Name')" if [ ! "$device" = "" ]; then echo "^c#81a1c1^^d^ $(echo "$device" | head -n 1 | xargs | cut -c 7-)" diff --git a/.local/bin/status-bar/date b/.local/bin/status-bar/date index 5aeb0cfa..0cc2cb01 100755 --- a/.local/bin/status-bar/date +++ b/.local/bin/status-bar/date @@ -8,7 +8,7 @@ else events="" fi -cmd=$(date +"%h%e") +cmd=$(date +"%h %e") echo -n "^c#0f111a^^b#88c0d0^ $icon $events$cmd ^d^" diff --git a/.local/bin/status-bar/mpc b/.local/bin/status-bar/mpc index 1bf3b432..0c7496a4 100755 --- a/.local/bin/status-bar/mpc +++ b/.local/bin/status-bar/mpc @@ -1,10 +1,10 @@ #!/bin/bash -online=$(mpc 2> /dev/null) -title=$(mpc -f "%title%" 2> /dev/null | head -n 1) -artist=$(mpc -f "%artist%" 2> /dev/null | head -n 1) +online=$(timeout 2 mpc 2> /dev/null) if [ ! "$online" = "" ]; then + title=$(mpc -f "%title%" 2> /dev/null | head -n 1) + artist=$(mpc -f "%artist%" 2> /dev/null | head -n 1) if [ "$(echo "$online" | wc -l)" -le 1 ]; then echo -n "^c#a48ead^ ^d^" else diff --git a/.local/bin/status-bar/network b/.local/bin/status-bar/network index 24b0c3c0..b4d77bb8 100755 --- a/.local/bin/status-bar/network +++ b/.local/bin/status-bar/network @@ -2,6 +2,18 @@ source ~/.config/config.env +get_ssid(){ + networks=$(connmanctl services | \ + awk -F ' +' '{ service_id=$NF; $NF=""; $1=""; name=substr($0, 2, length-2); gsub(/[^a-zA-Z0-9-]/, "_", name) } + name { print name, service_id }') + while read -r name service_id; do + if [ $(connmanctl services "$service_id" | awk '$1 == "State" { print $3 }') = "online" ]; then + echo "$name" + break + fi + done <<< "$networks" +} + is_eth_used=$(cat /sys/class/net/$ETH_IT/carrier) is_wlan_used=$(cat /sys/class/net/$WLAN_IT/carrier) @@ -10,7 +22,7 @@ echo -n "^c#88c0d0^" if [ "$is_eth_used" -eq 1 ]; then # wired network is carrying icon=" ^d^ " #uF6FF elif [ "$is_wlan_used" -eq 1 ]; then # wireless network is carrying - icon="直 ^d^ $(nmcli -t -f active,ssid dev wifi | egrep '^yes' | cut -d\' -f2 | cut -d ':' -f2)" #uF1EB + icon="直 ^d^ $(get_ssid)" #uF1EB else icon=" ^d^" #uf128 # no network fi diff --git a/.local/src/dwm/keybind.h b/.local/src/dwm/keybind.h index 00459521..74433cc2 100644 --- a/.local/src/dwm/keybind.h +++ b/.local/src/dwm/keybind.h @@ -69,13 +69,15 @@ static Key keys[] = { { MODKEY, XK_Return, spawn, {.v = termcmd } }, { MODKEY|ShiftMask, XK_Return, spawn, {.v = tmuxcmd } }, { MODKEY, XK_b, togglebar, {0} }, + { MODKEY, XK_k, focusstack, {.i = -1 } }, { MODKEY, XK_j, focusstack, {.i = +1 } }, { MODKEY|ShiftMask, XK_i, spawn, {.v = screensaver} }, { MODKEY|ShiftMask, XK_n, spawn, {.v = notification } }, - { MODKEY, XK_k, focusstack, {.i = -1 } }, - { MODKEY, XK_h, setmfact, {.f = -0.05} }, - { MODKEY, XK_l, setmfact, {.f = +0.05} }, - { MODKEY|ShiftMask, XK_Return, zoom, {0} }, + { MODKEY, XK_Right, setmfact, {.f = +0.05} }, + { MODKEY, XK_Left, setmfact, {.f = -0.05} }, + { MODKEY, XK_Down, setcfact, {.f = -0.25} }, + { MODKEY, XK_Up, setcfact, {.f = +0.25} }, + { MODKEY|ShiftMask, XK_z, zoom, {0} }, { MODKEY, XK_Tab, view, {0} }, { MODKEY, XK_q, killclient, {0} }, { MODKEY|Mod1Mask, XK_i, incnmaster, {.i = +1 } }, diff --git a/.local/src/dwm/patches.h b/.local/src/dwm/patches.h index ca329bb5..193f73b5 100644 --- a/.local/src/dwm/patches.h +++ b/.local/src/dwm/patches.h @@ -417,7 +417,7 @@ * respective stack in tiled layout. * https://dwm.suckless.org/patches/cfacts/ */ -#define CFACTS_PATCH 0 +#define CFACTS_PATCH 1 /* This patch allows color attributes to be set through the command line. * https://dwm.suckless.org/patches/cmdcustomize/ diff --git a/.profile b/.profile index bde6c2bb..5ea447e8 100755 --- a/.profile +++ b/.profile @@ -19,7 +19,6 @@ export XDG_CONFIG_HOME="$HOME"/.config export XDG_CACHE_HOME="$HOME"/.cache export XDG_DATA_DIRS="/usr/local/share:/usr/share" export XDG_CONFIG_DIRS="/etc/xdg" -export XDG_RUNTIME_DIR="/run/user/1000" # Cleanup Home Directory export HISTFILE="$XDG_DATA_HOME"/history @@ -92,7 +91,7 @@ fi # Start xinit if logged in from tty1 if [ "$DISPLAY" = "" ] && [ "$(tty)" = /dev/tty1 ]; then if [ "$DBUS_SESSION_BUS_ADDRESS" = "" ] && [ ! $(command -v dbus-launch) = "" ]; then - exec dbus-launch --exit-with-session xinit 2> $XDG_RUNTIME_DIR/xinit.err > $XDG_RUNTIME_DIR/xinit + exec dbus-run-session xinit 2> $XDG_RUNTIME_DIR/xinit.err > $XDG_RUNTIME_DIR/xinit else exec xinit 2> $XDG_RUNTIME_DIR/xinit.err > $XDG_RUNTIME_DIR/xinit fi