diff options
author | justsaumit <justsaumit@draconyan.xyz> | 2022-02-27 07:00:19 +0530 |
---|---|---|
committer | justsaumit <justsaumit@draconyan.xyz> | 2022-02-27 07:00:19 +0530 |
commit | b7c8da835bb251862a3b2b23458bd2f4c5f58f5f (patch) | |
tree | 5b934e387371202fb2bf9fb689b254bacfe354ac /scripts | |
parent | 7eb981e3ac9742ed1fefe49e7ef058f783e63f76 (diff) |
Pushing old local updates
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/dmount | 67 | ||||
-rwxr-xr-x | scripts/dumount | 44 | ||||
-rwxr-xr-x | scripts/emojiselw | 19 | ||||
-rwxr-xr-x | scripts/fmenu | 77 | ||||
-rwxr-xr-x | scripts/hotrebootdwm | 4 | ||||
-rwxr-xr-x | scripts/prompt | 9 | ||||
-rw-r--r-- | scripts/setbg | 3 | ||||
-rw-r--r-- | scripts/vpn-menu | 2 |
8 files changed, 222 insertions, 3 deletions
diff --git a/scripts/dmount b/scripts/dmount new file mode 100755 index 0000000..3cb1f81 --- /dev/null +++ b/scripts/dmount @@ -0,0 +1,67 @@ +#!/bin/sh + +# Gives a dmenu prompt to mount unmounted drives and Android phones. If +# they're in /etc/fstab, they'll be mounted automatically. Otherwise, you'll +# be prompted to give a mountpoint from already existsing directories. If you +# input a novel directory, it will prompt you to create that directory. + +getmount() { \ + [ -z "$chosen" ] && exit 1 + # shellcheck disable=SC2086 + mp="$(find $1 2>/dev/null | dmenu -i -p "Type in mount point.")" || exit 1 + test -z "$mp" && exit 1 + if [ ! -d "$mp" ]; then + mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") || exit 1 + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") + fi + } + +mountusb() { \ + chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1}')" + sudo -A mount "$chosen" 2>/dev/null && notify-send "💻 USB mounting" "$chosen mounted." && exit 0 + alreadymounted=$(lsblk -nrpo "name,type,mountpoint" | awk '$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not ( -path *%s -prune ) ",$3}') + getmount "/mnt /media /mount /home -maxdepth 5 -type d $alreadymounted" + partitiontype="$(lsblk -no "fstype" "$chosen")" + case "$partitiontype" in + "vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;; + "exfat") sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)";; + *) sudo -A mount "$chosen" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";; + esac + notify-send "💻 USB mounting" "$chosen mounted to $mp." + } + +mountandroid() { \ + chosen="$(echo "$anddrives" | dmenu -i -p "Which Android device?")" || exit 1 + chosen="$(echo "$chosen" | cut -d : -f 1)" + getmount "$HOME -maxdepth 3 -type d" + simple-mtpfs --device "$chosen" "$mp" + echo "OK" | dmenu -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 + simple-mtpfs --device "$chosen" "$mp" + notify-send "🤖 Android Mounting" "Android device mounted to $mp." + } + +asktype() { \ + choice="$(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?")" || exit 1 + case $choice in + USB) mountusb ;; + Android) mountandroid ;; + esac + } + +anddrives=$(simple-mtpfs -l 2>/dev/null) +usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom' | awk '$4==""{printf "%s (%s)\n",$1,$3}')" + +if [ -z "$usbdrives" ]; then + [ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit + echo "Android device(s) detected." + mountandroid +else + if [ -z "$anddrives" ]; then + echo "USB drive(s) detected." + mountusb + else + echo "Mountable USB drive(s) and Android device(s) detected." + asktype + fi +fi diff --git a/scripts/dumount b/scripts/dumount new file mode 100755 index 0000000..946d12c --- /dev/null +++ b/scripts/dumount @@ -0,0 +1,44 @@ +#!/bin/sh + +# A dmenu prompt to unmount drives. +# Provides you with mounted partitions, select one to unmount. +# Drives mounted at /, /boot and /home will not be options to unmount. + +unmountusb() { + [ -z "$drives" ] && exit + chosen="$(echo "$drives" | dmenu -i -p "Unmount which drive?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1}')" + [ -z "$chosen" ] && exit + sudo -A umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted." + } + +unmountandroid() { \ + chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")" || exit 1 + [ -z "$chosen" ] && exit + sudo -A umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted." + } + +asktype() { \ + choice="$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" || exit 1 + case "$choice" in + USB) unmountusb ;; + Android) unmountandroid ;; + esac + } + +drives=$(lsblk -nrpo "name,type,size,mountpoint,label" | awk -F':' '{gsub(/ /,":")}$4!~/\/boot|\/efi|\/home$|SWAP/&&length($4)>1{printf "%s (%s) %s\n",$4,$3,$5}') + +if ! grep simple-mtpfs /etc/mtab; then + [ -z "$drives" ] && echo "No drives to unmount." && exit + echo "Unmountable USB drive detected." + unmountusb +else + if [ -z "$drives" ] + then + echo "Unmountable Android device detected." + unmountandroid + else + echo "Unmountable USB drive(s) and Android device(s) detected." + asktype + fi +fi diff --git a/scripts/emojiselw b/scripts/emojiselw new file mode 100755 index 0000000..9e6f055 --- /dev/null +++ b/scripts/emojiselw @@ -0,0 +1,19 @@ +#!/bin/sh + +# The famous "get a menu of emojis to copy" script. + +# Get user selection via dmenu from emoji file. +windowsid=$(xdotool getactivewindow) +chosen=$(cut -d ';' -f1 ~/.local/share/emoji | dmenu -i -l 30 -w $windowsid | sed "s/ .*//") +# Exit if none chosen. +[ -z "$chosen" ] && exit + +# If you run this command with an argument, it will automatically insert the +# character. Otherwise, show a message that the emoji has been copied. +if [ -n "$1" ]; then + xdotool type "$chosen" +else + printf "$chosen" | xclip -sel c + notify-send "'$chosen' copied to clipboard." & +fi + diff --git a/scripts/fmenu b/scripts/fmenu new file mode 100755 index 0000000..d0c6fce --- /dev/null +++ b/scripts/fmenu @@ -0,0 +1,77 @@ +#!/bin/bash + +usage() +{ + cat << EOF +usage: $0 options + +Index and search files using dmenu + +OPTIONS: + -h Show this message + -o Store index [default: /tmp/fmenu_index] + -i Search folders [default: $HOME] + -x Exclude files [default: ".*\/..*" (i.e. dot-files)] + -d dmenu parameters [default: -i -l 20] + -f force reloading index [default: false] + -t time [default: 5min] + -u Just update the index +EOF +} + +FORCE=false +INDEX="/tmp/fmenu_index" +DMENU="-i -l 20" +TIME="+5" +INPUT=$HOME +EXCLUDE='.*/\..*' +DRY=false +while getopts "ht:fd:o:i:x:u" OPTION +do + case $OPTION in + h) + usage + exit 1 + ;; + f) + FORCE=true + ;; + d) + DMENU=$OPTARG + ;; + t) + TIME=$OPTARG + ;; + o) + INDEX=$OPTARG + ;; + i) + INPUT=$OPTARG + ;; + x) + EXCLUDE=$OPTARG + ;; + u) + FORCE=true + DRY=true + ;; + ?) + usage + exit + ;; + esac +done + +function index_files { + find "$INPUT" \( ! -regex "$EXCLUDE" \) | sed 's/ /\\ /g' | sort -f > "$INDEX" +} + +if [[ ! -a "$INDEX" ]] || ( test `find $INDEX -mmin $TIME` ) || ($FORCE) +then + index_files +fi + +if ( ! $DRY ) +then + cat "$INDEX" | `dmenu $DMENU > /tmp/dmenu_find_output.txt` && cat /tmp/dmenu_find_output.txt | xargs xdg-open +fi diff --git a/scripts/hotrebootdwm b/scripts/hotrebootdwm new file mode 100755 index 0000000..b89bac7 --- /dev/null +++ b/scripts/hotrebootdwm @@ -0,0 +1,4 @@ +$!/bin/sh +##pid=$(ps -a | grep dwm | awk '{print $1}') +pid=$(pidof dwm) +kill -HUP $pid diff --git a/scripts/prompt b/scripts/prompt new file mode 100755 index 0000000..9549658 --- /dev/null +++ b/scripts/prompt @@ -0,0 +1,9 @@ +#!/bin/sh +# A dmenu binary prompt script +# Gives dmenu prompt labeled with $1 to perform command $2 +# For example: +# './promptquit "Do you really want to quit?" "shutdown -h now"' + +[ $(echo -e "No\nYes" | dmenu -i -p "$1") \ + == "Yes" ] && $2 + diff --git a/scripts/setbg b/scripts/setbg index 0e3e180..7437005 100644 --- a/scripts/setbg +++ b/scripts/setbg @@ -6,10 +6,9 @@ echo "Setting up the wallpaper: $(echo $wall|cut -d '/' -f 8)" xwallpaper --zoom $wall echo "Generating pywal color schemes..." wal -n -i $wall >/dev/null -#sed -i $HOME/.cache/wal/colors-wol-dwm.h -#echo "Recompiling dwm w new colors..." echo "dwm reading Xresources color values at runtime" xdotool key super+F5 pywal-discord +$HOME/.local/usr/wal-telegram/wal-telegram #(cd $HOME/.local/src/dwm && sudo make clean install>/dev/null) echo "^_^ Enjoy your new look!!!" diff --git a/scripts/vpn-menu b/scripts/vpn-menu index 1862205..87d429b 100644 --- a/scripts/vpn-menu +++ b/scripts/vpn-menu @@ -1,5 +1,5 @@ #!/bin/sh vpnid=$(nmcli con | grep "vpn" | cut -d " " -f 1 | dmenu -p "Select VPN to activate/deactivate") -actdeact=$(echo "" | dmenu -p "Activate or Deactivate? (up or down)") +actdeact=$(echo -e "up\ndown" | dmenu -p "Activate or Deactivate? (up or down)") nmcli con $actdeact id $vpnid |