From 34841dbbfdd4102f2cde6ef18c26b211bc69e722 Mon Sep 17 00:00:00 2001 From: Yigit Colakoglu Date: Wed, 12 Jan 2022 16:49:43 +0100 Subject: [PATCH] Edited several scripts and dwm --- .local/bin/dmenu-books | 50 +++++++++++++++-------------- .local/bin/dmenu-mconnect | 57 ++++++++++++++++------------------ .local/bin/status-bar/mconnect | 7 ++--- .local/bin/status-bar/todo | 4 ++- .local/src/dwm/config.h | 2 -- .local/src/dwm/config.mk | 2 ++ .local/src/dwm/keybinds.h | 1 - .local/src/dwm/rules.h | 2 ++ 8 files changed, 63 insertions(+), 62 deletions(-) diff --git a/.local/bin/dmenu-books b/.local/bin/dmenu-books index cb3906ca..c4384851 100755 --- a/.local/bin/dmenu-books +++ b/.local/bin/dmenu-books @@ -3,35 +3,37 @@ # This is a small script to open a book from your calibre library # Using dmenu. -LIBRARY="$HOME/Library" +USERNAME="yigitcolakoglu" +PASSWORD="$(pass show Server/calibre.yigitcolakoglu.com/yigitcolakoglu)" +HOST="https://calibre.fr1nge.xyz" -if [ "$(date -r "$XDG_CACHE_HOME/calibrelib" "+%d-%m-%Y")" = "$(date '+%d-%m-%Y')" ]; then - books_raw=$(cat "$XDG_CACHE_HOME/calibrelib") -else - books_raw=$(calibredb --with-library "$LIBRARY" list --for-machine --fields="title,authors,formats") - echo "$books_raw" > "$XDG_CACHE_HOME/calibrelib" -fi +function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; } -id="$(echo "$books_raw" |\ - jq -r '.[]|(.id | tostring) + " | " + .title + " | " + .authors' |\ - dmenu -i -l 12 -p "Search Book: " |\ - cut -d "|" -f 1)" +query=$(printf "" | dmenu -p "Please enter the book's name") +[ -z $query ] && exit -entry="$(echo "$books_raw" | jq -a ".[]|select(.id | contains($id))")" +XML=$(curl -s -u "$USERNAME:$PASSWORD" "$HOST/opds/search?query=$query") -formats="$(echo "$entry" | \ - jq -r ".formats|.[]" |\ - sed -r "s/.*\.([^\.]*)$/\1/g")" +menu=$(echo $XML | xpath -q -e '//entry/title | //entry/author/name | //entry/link[@type="application/pdf"]/@href') -if [ "$(echo "$formats" | wc -l)" -lt 2 ]; then - xdg-open "$(echo "$entry" | \ - jq -r ".formats|.[0]")" - exit -fi +book=$(echo "$menu" | \ +sed 's/\(.*\)<\/title>/\1|/;N;s/<name>\(.*\)<\/name>/\1|/;N;s/href="\(.*\)"/\1/;s/\n/ /g' | \ +column -s '|' -t | dmenu -p "Please select the book" -l 5) -index=$(( $(echo "$formats" | grep -n -F $(echo "$formats" | \ - dmenu -p "Select format:" ) | cut -d ":" -f 1) - 1)) +[ -z "$book" ] && exit -xdg-open "$(echo "$entry" | \ - jq -r ".formats|.[$line]")" +name=$(echo "$book" | sed 's/\s\{2,\}/\n/g' | head -n 1) +author=$(echo "$book" | sed 's/\s\{2,\}/\n/g' | head -n 2 | tail -n 1) +path=$(echo "$book" | sed 's/\s\{2,\}/\n/g' | tail -n 1) +mkdir -p "$XDG_RUNTIME_DIR/books" +notify-send -a " Downloading" "$(printf "%s\n%s" "$name" "$author")" + +wget -nc -P "$XDG_RUNTIME_DIR/books" -q --content-disposition \ + --user "$USERNAME" --password "$PASSWORD" "$HOST$path" + +filename=$(curl -s --head -u "$USERNAME:$PASSWORD" "$HOST$path" | \ + grep "Content-Disposition" |\ + sed -E 's/Content-Disposition:.*filename=([^;]*);.*/\1/g') + +xdg-open "$XDG_RUNTIME_DIR/books/$(urldecode $filename)" diff --git a/.local/bin/dmenu-mconnect b/.local/bin/dmenu-mconnect index 02bd6ab0..9a569e8e 100755 --- a/.local/bin/dmenu-mconnect +++ b/.local/bin/dmenu-mconnect @@ -44,35 +44,32 @@ SEPERATOR='|' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +source ~/.config/config.env + show_devices (){ - IFS=$',' - devices="" - # for all the devices avalable - for device in $(dbus-send --print-reply --session --dest=org.mconnect /org/mconnect/manager org.mconnect.DeviceManager.ListDevices | cut -f1 -d"[" | cut -f1 -d "]" | tail -2); do - #get the device info - deviceobj=$(echo "$device" | cut -f2 -d"\"" | tr -d '\n' | xargs) - devicename=$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:Name | grep -E string | cut -f2 -d"\"") - isreach="$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:IsConnected | grep -E boolean | cut -b 26-)" - devicetype=$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:DeviceType | grep -E string | cut -f2 -d"\"") - istrust="$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:Allowed | grep -E boolean | cut -b 26-)" - if [ "$isreach" = "true" ] && [ "$istrust" = "true" ];then - #is connected - battery="$(dbus-send --print-reply --session --dest=org.mconnect $deviceobj org.freedesktop.DBus.Properties.Get string:org.mconnect.Device.Battery string:Level | grep -e uint32 | cut -b 25-)%" - icon=$(get_icon $battery $devicetype) - # colors="$(get_colors $battery)" - # echo "$colors" - show_menu "$devicename | $battery $icon" $deviceobj $battery - devices+="$devicename $battery $icon $SEPERATOR" - elif [ "$isreach" = "false" ] && [ "$istrust" = "true" ];then - #nothing is found - devices+="$(get_icon -1 $devicetype)$SEPERATOR" - else - #found but not yet paired - icon=$(get_icon -2 $devicetype) - show_pmenu $devicename $deviceobj - devices+="$devicename $icon $SEPERATOR" - fi - done + device=$(mconnectctl | grep $MCONNECT_DEVICE | sed 's/\s\{2,\}/\n/g; s/ - /\n/g;s/^\n//g' | head -n 1) + deviceobj=$(echo "$device" | cut -f2 -d"\"" | tr -d '\n' | xargs) + devicename=$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:Name | grep -E string | cut -f2 -d"\"") + isreach="$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:IsConnected | grep -E boolean | cut -b 26-)" + devicetype=$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:DeviceType | grep -E string | cut -f2 -d"\"") + istrust="$(dbus-send --print-reply --session --dest=org.mconnect "$deviceobj" org.freedesktop.DBus.Properties.Get string:org.mconnect.Device string:Allowed | grep -E boolean | cut -b 26-)" + if [ "$isreach" = "true" ] && [ "$istrust" = "true" ];then + #is connected + battery="$(dbus-send --print-reply --session --dest=org.mconnect $deviceobj org.freedesktop.DBus.Properties.Get string:org.mconnect.Device.Battery string:Level | grep -e uint32 | cut -b 25-)%" + icon=$(get_icon $battery $devicetype) + # colors="$(get_colors $battery)" + # echo "$colors" + show_menu "$devicename | $battery $icon" $deviceobj $battery + devices+="$devicename $battery $icon $SEPERATOR" + elif [ "$isreach" = "false" ] && [ "$istrust" = "true" ];then + #nothing is found + devices+="$(get_icon -1 $devicetype)$SEPERATOR" + else + #found but not yet paired + icon=$(get_icon -2 $devicetype) + show_pmenu $devicename $deviceobj + devices+="$devicename $icon $SEPERATOR" + fi } SendKeys(){ @@ -89,8 +86,8 @@ SendKeys(){ #displays a menu for the connected device show_menu () { optionNum=5 - options=$(printf "Send SMS\\nSend File\\nSend Text\\nSend URL\\nDisconnect\\n") - menu=$(echo $options | dmenu -i -p $1 -l $optionNum ) + options="Send SMS\nSend File\nSend Text\nSend URL\nDisconnect\n" + menu=$(printf "$options" | dmenu -i -p "$1" -l $optionNum ) case "$menu" in *'Send File') mkdir -p $XDG_RUNTIME_DIR/lf/ diff --git a/.local/bin/status-bar/mconnect b/.local/bin/status-bar/mconnect index a3cc8ae5..dc70b005 100755 --- a/.local/bin/status-bar/mconnect +++ b/.local/bin/status-bar/mconnect @@ -4,11 +4,11 @@ if ! xdpyinfo | grep -q VNC ; then source ~/.config/config.env if [ ! "$MCONNECT" = true ] ; then - echo "^c#EBCB8B^ ^d^" exit 0 fi - device_status=$(mconnectctl show-device $MCONNECT_DEVICE) + device=$(mconnectctl | grep $MCONNECT_DEVICE | sed 's/\s\{2,\}/\n/g; s/ - /\n/g;s/^\n//g' | head -n 1) + device_status=$(mconnectctl show-device $device) IFS=$'\n' @@ -18,11 +18,10 @@ if ! xdpyinfo | grep -q VNC ; then connected=${connected[1]} if [ ! "$connected" = true ] ; then - echo "^c#EBCB8B^ ^d^" exit 0 fi - battery_status=$(mconnectctl show-battery $MCONNECT_DEVICE) + battery_status=$(mconnectctl show-battery $device) IFS=$'\n' diff --git a/.local/bin/status-bar/todo b/.local/bin/status-bar/todo index 17ef587c..b64264ec 100755 --- a/.local/bin/status-bar/todo +++ b/.local/bin/status-bar/todo @@ -2,5 +2,7 @@ todos=$(calcurse -t | tail -n +2 | wc -l) -echo -n "^c#81a1c1^ ^d^ $todos" +if [ ! "$todos" = "0" ]; do + echo -n "^c#81a1c1^ ^d^ $todos" +done diff --git a/.local/src/dwm/config.h b/.local/src/dwm/config.h index 5ab26c74..058b4473 100644 --- a/.local/src/dwm/config.h +++ b/.local/src/dwm/config.h @@ -48,7 +48,6 @@ const char *spcmd3[] = {"st", "-c", "scratchpad", "-n", "spmutt", "-g", "180x51" static const char *spcmd4[] = { "/usr/local/bin/st", "-g", "150x35", "-c", "spfile", "-n", "spfile", "-e", "/home/yigit/.local/bin/lf-ueberzug", NULL }; static const char *spcmd5[] = { "/usr/local/bin/st", "-g", "150x35", "-c", "spmusic", "-n", "spmusic", "-e", "ncmpcpp", NULL }; static const char *spcmd6[] = { "/usr/local/bin/st", "-g", "150x35", "-c", "spcal", "-n", "spcal", "-e", "calcurse", NULL }; -static const char *spcmd7[] = { "obsidian" }; static Sp scratchpads[] = { {"spterm", spcmd1}, @@ -57,7 +56,6 @@ static Sp scratchpads[] = { {"spfile", spcmd4}, {"spmusic", spcmd5}, {"spcal", spcmd6}, - {"obsidian", spcmd7}, }; /* key definitions */ diff --git a/.local/src/dwm/config.mk b/.local/src/dwm/config.mk index 54e61dd1..c2eec936 100644 --- a/.local/src/dwm/config.mk +++ b/.local/src/dwm/config.mk @@ -1,3 +1,5 @@ +VPS ?= 0 + # dwm version VERSION = 6.2 diff --git a/.local/src/dwm/keybinds.h b/.local/src/dwm/keybinds.h index b0ca8313..2d0ab295 100644 --- a/.local/src/dwm/keybinds.h +++ b/.local/src/dwm/keybinds.h @@ -171,7 +171,6 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_f, togglescratch, {.ui = 3} }, { MODKEY, XK_n, togglescratch, {.ui = 4} }, { MODKEY|ShiftMask, XK_c, togglescratch, {.ui = 5} }, - { MODKEY, XK_o, togglescratch, {.ui = 6} }, /* FloatPos Patch Keybinds */ { Mod3Mask, XK_u, floatpos, {.v = "-26x -26y" } }, // ↖ { Mod3Mask, XK_i, floatpos, {.v = " 0x -26y" } }, // ↑ diff --git a/.local/src/dwm/rules.h b/.local/src/dwm/rules.h index d03b6e30..7b9b0f28 100644 --- a/.local/src/dwm/rules.h +++ b/.local/src/dwm/rules.h @@ -46,6 +46,8 @@ static const Rule rules[] = { { "Zathura" , NULL , NULL , 0 , 0 , NULL , 0 , 1 , -1 }, { "Qemu-system-x86_64", NULL , NULL , 0 , 1 , NULL , 0 , 1 , -1 }, { "spfeh" , NULL , NULL , SPTAG(1) , 1 , NULL , 0 , 0 , -1 }, +{ "obsidian" , NULL , NULL , 1 << 4 , 0 , NULL , 0 , 1 , -1 }, +{ "spfeh" , NULL , NULL , SPTAG(1) , 1 , NULL , 0 , 0 , -1 }, { NULL , "spterm" , NULL , SPTAG(0) , 1 , NULL , 0 , 0 , -1 }, { NULL , "spmutt" , NULL , SPTAG(2) , 1 , NULL , 0 , 0 , -1 }, { NULL , "spfile" , NULL , SPTAG(3) , 1 , NULL , 0 , 0 , -1 },