scripts sorted

This commit is contained in:
Luke Smith
2018-11-05 17:51:24 -05:00
parent cd667e6aa1
commit 2f4c2a68a1
64 changed files with 273 additions and 331 deletions

17
.scripts/i3cmds/bottomleft Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# This script move the selected window to the bottom left of the screen.
current=$(xdotool getwindowfocus)
# The window will take up no more than a third of
# the width or height of the screen.
newwidth=$(($(xdotool getdisplaygeometry | awk '{print $2}') / 3))
newheight=$(($(xdotool getdisplaygeometry | awk '{print $1}') / 3))
xdotool windowsize $(xdotool getwindowfocus) $newheight $newwidth
newsize=$(xdotool getwindowgeometry $(xdotool getwindowfocus) | grep Geometry | sed -e 's/x/ /g' | awk '{print $3}')
height=$(($(xdotool getdisplaygeometry | awk '{print $2}') - newsize))
xdotool windowmove $current 0 $height

18
.scripts/i3cmds/bottomright Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/sh
# This script move the selected window to the bottom left of the screen.
current=$(xdotool getwindowfocus)
# The window will take up no more than a third of
# the width or height of the screen.
newwidth=$(($(xdotool getdisplaygeometry | awk '{print $2}') / 3))
newheight=$(($(xdotool getdisplaygeometry | awk '{print $1}') / 3))
xdotool windowsize "$(xdotool getwindowfocus)" $newheight $newwidth
newsize=$(xdotool getwindowgeometry "$(xdotool getwindowfocus)" | grep Geometry | sed -e 's/x/ /g' | awk '{print $3}')
newwidth=$(xdotool getwindowgeometry "$(xdotool getwindowfocus)" | grep Geometry | grep -o " [0-9]*")
vertical=$(($(xdotool getdisplaygeometry | awk '{print $2}') - newsize))
horizontal=$(($(xdotool getdisplaygeometry | awk '{print $1}') - newwidth))
xdotool windowmove "$current" $horizontal $vertical

2
.scripts/i3cmds/camtoggle Executable file
View File

@@ -0,0 +1,2 @@
#!/bin/bash
pkill -f /dev/video || mpv --no-osc --no-input-default-bindings --input-conf=/dev/null --geometry=-0-0 --autofit=30% --title="mpvfloat" /dev/video0

26
.scripts/i3cmds/ddspawn Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/sh
# This script simplifies dropdown windows in i3.
# Shows/hides a scratchpad of a given name, if it doesn't exist, creates it.
# Usage:
# argument 1: script to run in dropdown window
# all other args are interpreted as options for your terminal
# My usage:
# ddpawn
# bindsym $mod+u exec --no-startup-id ddspawn tmuxdd
# Will hide/show window running the `tmuxdd` script when I press mod+u in i3
# bindsym $mod+a exec --no-startup-id ddspawn dropdowncalc -f mono:pixelsize=24
# Similar to above but with `dropdowncalc` and the other args are interpretated as for my terminal emulator (to increase font)
[ -z "$1" ] && exit
if xwininfo -tree -root | grep "(\"$1\" ";
then
echo "Window detected."
else
echo "Window not detected... spawning."
i3 "exec --no-startup-id $TERMINAL -n $1 $(echo "$@" | cut -d ' ' -f2-) -e $1" && i3 "[instance=\"$1\"] scratchpad show; [instance=\"$1\"] move position center"
sleep .25 # This sleep is my laziness, will fix later (needed for immediate appearance after spawn).
fi
i3 "[instance=\"$1\"] scratchpad show; [instance=\"$1\"] move position center"

49
.scripts/i3cmds/displayselect Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/sh
# A UI for detecting and selecting all displays.
# Probes xrandr for connected displays and lets user select one to use.
# User may also select "manual selection" which opens arandr.
# I plan on adding a routine from multi-monitor setups later.
twoscreen() { # If multi-monitor is selected and there are two screens.
primary=$(echo "$screens" | dmenu -i -p "Select primary display:")
secondary=$(echo "$screens" | grep -v "$primary")
direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?")
xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto
}
morescreen() { # If multi-monitor is selected and there are more than two screens.
primary=$(echo "$screens" | dmenu -i -p "asdf")
secondary=$(echo "$screens" | grep -v "$primary" | dmenu -i -p "Select secondary display:")
direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?")
tertiary=$(echo "$screens" | grep -v "$primary" | grep -v "$secondary" | dmenu -i -p "Select third display:")
xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto
}
multimon() { # Multi-monitor handler.
case "$(echo "$screens" | wc -l)" in
1) xrandr $(echo "$allposs" | awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;;
2) twoscreen ;;
*) morescreen ;;
esac ;}
# Get all possible displays
allposs=$(xrandr -q | grep "connected")
# Get all connected screens.
screens=$(echo "$allposs" | grep " connected" | awk '{print $1}')
# Get user choice including multi-monitor and manual selection:
chosen=$(printf "%s\\nmulti-monitor\\nmanual selection" "$screens" | dmenu -i -p "Select display arangement:") &&
case "$chosen" in
"manual selection") arandr ; exit ;;
"multi-monitor") multimon ;;
*) xrandr --output "$chosen" --auto $(echo "$screens" | grep -v "$chosen" | awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;;
esac
# Fix feh background if screen size/arangement has changed.
feh --bg-scale "$HOME/.config/wall.png"
# Polybar users will want to uncomment this line, which reactivates polybar on all new displays:
#polybar_launch
# Re-remap keys if keyboard added (for laptop bases)
remaps

54
.scripts/i3cmds/dmenumount Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/sh
# Gives a dmenu prompt to mount unmounted drives.
# 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.
pgrep -x dmenu && exit
getmount() { \
[ -z "$chosen" ] && exit 1
mp="$(find $1 | dmenu -i -p "Type in mount point.")"
[ "$mp" = "" ] && exit 1
if [ ! -d "$mp" ]; then
mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?")
[ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp")
fi
}
mountusb() { \
chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?" | awk '{print $1}')"
sudo -A mount "$chosen" && exit 0
getmount "/mnt /media /mount /home -maxdepth 5 -type d"
sudo -A mount "$chosen" "$mp" && pgrep -x dunst && notify-send "$chosen mounted to $mp."
}
mountandroid() { \
chosen=$(echo "$anddrives" | dmenu -i -p "Which Android device?" | cut -d : -f 1)
getmount "$HOME -maxdepth 3 -type d"
simple-mtpfs --device "$chosen" "$mp"
echo simple-mtpfs --device "$chosen" "$mp"
}
asktype() { \
case $(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?") in
USB) mountusb ;;
Android) mountandroid ;;
esac
}
anddrives=$(simple-mtpfs -l 2>/dev/null)
usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | awk '$2=="part"&&$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

105
.scripts/i3cmds/dmenurecord Executable file
View File

@@ -0,0 +1,105 @@
#!/bin/sh
# Usage:
# `record`: Ask for recording type via dmenu
# `record screencast`: Record both audio and screen
# `record video`: Record only screen
# `record audio`: Record only audio
# `record kill`: Kill existing recording
#
# If there is already a running instance, user will be prompted to end it.
updateicon() { \
echo "$1" > ~/.recordingicon
pkill -RTMIN+9 i3blocks
}
killrecording() {
recpid="$(cat ~/.recordingpid)"
# kill with SIGTERM, allowing finishing touches.
kill -15 "$recpid"
rm -f ~/.recordingpid
updateicon ""
pkill -RTMIN+9 i3blocks
# even after SIGTERM, ffmpeg may still run, so SIGKILL it.
sleep 3
kill -9 "$recpid"
exit
}
screencastpulse() { \
ffmpeg -y \
-f x11grab \
-framerate 60 \
-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
-i :0.0 \
-f alsa -i default \
-r 30 \
-c:v libx264rgb -crf 0 -preset ultrafast -c:a flac \
"$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mkv" &
echo $! > ~/.recordingpid
updateicon "⏺️🎙️"
}
screencastalsa() { \
ffmpeg -y \
-f x11grab \
-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
-i :0.0 \
-thread_queue_size 1024 \
-f alsa -ar 44100 -i hw:1 \
-c:v libx264 -r 30 -c:a flac \
"$HOME/screencast-$(date '+%y%m%d-%H%M-%S').mkv" &
echo $! > ~/.recordingpid
updateicon "⏺️"
}
video() { ffmpeg \
-f x11grab \
-s $(xdpyinfo | grep dimensions | awk '{print $2;}') \
-i :0.0 \
-c:v libx264 -qp 0 -r 30 \
"$HOME/video-$(date '+%y%m%d-%H%M-%S').mkv" &
echo $! > ~/.recordingpid
updateicon "⏺️"
}
audiopulse() { \
ffmpeg \
-f alsa -i default \
-c:a flac \
"$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" &
echo $! > ~/.recordingpid
updateicon "🎙️"
}
audioalsa() { \
ffmpeg -y \
-f alsa -ar 44100 -i hw:1 \
"$HOME/audio-$(date '+%y%m%d-%H%M-%S').flac" &
echo $! > ~/.recordingpid
updateicon "🎙️"
}
askrecording() { \
choice=$(printf "screencast\\nvideo\\naudio" | dmenu -i -p "Select recording style:")
case "$choice" in
screencast) screencastpulse;;
audio) audiopulse;;
video) video;;
esac
}
asktoend() { \
response=$(printf "No\\nYes" | dmenu -i -p "Recording still active. End recording?") &&
[ "$response" = "Yes" ] && killrecording
}
case "$1" in
screencast) screencastpulse;;
audio) audiopulse;;
video) video;;
kill) killrecording;;
*) ([ -f ~/.recordingpid ] && asktoend && exit) || askrecording;;
esac

36
.scripts/i3cmds/dmenuumount Executable file
View File

@@ -0,0 +1,36 @@
#!/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?" | awk '{print $1}')
[ -z "$chosen" ] && exit
sudo -A umount "$chosen" && pgrep -x dunst && notify-send "$chosen unmounted."
}
unmountandroid() { \
chosen=$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")
[ -z "$chosen" ] && exit
fusermount -u "$chosen" && pgrep -x dunst && notify-send "$chosen unmounted."
}
asktype() { \
case $(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?") in
USB) unmountusb ;;
Android) unmountandroid ;;
esac
}
drives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$2=="part"&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}')
if ! grep simple-mtpfs /etc/mtab; then
[ -z "$drives" ] && echo "No drives to unmount." && exit
echo "Unmountable USB drive detected."
unmountusb
else
[ -z "$drives" ] && echo "Unmountable Android device detected." && unmountandroid
echo "Unmountable USB drive(s) and Android device(s) detected."
asktype
fi

18
.scripts/i3cmds/dmenuunicode Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/sh
# Give dmenu list of all unicode characters to copy.
# Shows the selected character in dunst if running.
# Must have xclip installed to even show menu.
xclip -h >/dev/null || exit
chosen=$(grep -v "#" ~/.emoji | dmenu -i -l 20 -fn Monospace-18)
[ "$chosen" != "" ] || exit
c=$(echo "$chosen" | sed "s/ .*//")
echo "$c" | tr -d '\n' | xclip -selection clipboard
pgrep -x dunst >/dev/null && notify-send "'$c' copied to clipboard."
s=$(echo "$chosen" | sed "s/.*; //" | awk '{print $1}')
echo "$s" | tr -d '\n' | xclip
pgrep -x dunst >/dev/null && notify-send "'$s' copied to primary."

5
.scripts/i3cmds/dropdowncalc Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
# This script ensures that i3 will spawn a calculator.
# If R is installed, it will run R, otherwise it will run
# Python.
([ -e /usr/bin/R ] && R -q --no-save) || python -q

15
.scripts/i3cmds/ducksearch Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
# Gives a dmenu prompt to search DuckDuckGo.
# Without input, will open DuckDuckGo.com.
# Anything else, it search it.
pgrep -x dmenu && exit
choice=$(echo "🦆" | dmenu -i -p "Search DuckDuckGo:") || exit 1
if [ "$choice" = "🦆" ]; then
$BROWSER "https://duckduckgo.com"
else
$BROWSER "https://duckduckgo.com/?q=$choice&t=ffab&atb=v1-1"
fi

27
.scripts/i3cmds/i3resize Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
# This script was made by `goferito` on Github.
# Some cleanup by Luke.
[ -z "$1" ] && echo "No direction provided" && exit 1
distanceStr="2 px or 2 ppt"
moveChoice() {
i3-msg resize "$1" "$2" "$distanceStr" | grep '"success":true' || \
i3-msg resize "$3" "$4" "$distanceStr"
}
case $1 in
up)
moveChoice grow up shrink down
;;
down)
moveChoice shrink up grow down
;;
left)
moveChoice shrink right grow left
;;
right)
moveChoice grow right shrink left
;;
esac

7
.scripts/i3cmds/killrecording Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
kill -9 "$(cat ~/.recordingpid)"
# Update i3bar.
echo "" > ~/.recordingicon
pkill -RTMIN+9 i3blocks

19
.scripts/i3cmds/lockscreen Executable file
View File

@@ -0,0 +1,19 @@
#!/bin/sh
rm -f /tmp/locked.png
# If `imagemagick` is not installed, use a blank screen.
[ -f /usr/bin/convert ] &&
scrot -m -z /tmp/base.png &&
pgrep -x dunst && notify-send -i ~/.scripts/pix/lock.png "Locking computer..." &&
convert /tmp/base.png -blur 0x8 /tmp/locked.png
# Pause music (mocp, mpd and send the pause key to all mpv videos):
mocp -P >/dev/null 2>&1
mpc pause >/dev/null 2>&1
pauseallmpv >/dev/null 2>&1
i3lock -e -f -c 000000 -i /tmp/locked.png
# In five seconds, turn off display unless key press in last 4 seconds.
sleep 5 && [ 4000 -lt "$(xssstate -i)" ] && pgrep -x i3lock && xset dpms force off

5
.scripts/i3cmds/newspod Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/sh
# Another script because i3 is too dumb to call basic operations right.
# Brings up newsboat, if newsboat is open, opens podboat
newsboat || podboat

7
.scripts/i3cmds/prompt Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
# A dmenu binary prompt script.
# Gives a dmenu prompt labeled with $1 to perform command $2.
# For example:
# `./prompt "Do you want to shutdown?" "shutdown -h now"`
[ "$(printf "No\\nYes" | dmenu -i -p "$1" -nb darkred -sb red -sf white -nf gray )" = "Yes" ] && $2

27
.scripts/i3cmds/samedir Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/bash
# i3 thread: https://faq.i3wm.org/question/150/how-to-launch-a-terminal-from-here/?answer=152#post-id-152
CMD=$TERMINAL
CWD=''
# Get window ID
ID=$(xdpyinfo | grep focus | cut -f4 -d " ")
# Get PID of process whose window this is
PID=$(xprop -id $ID | grep -m 1 PID | cut -d " " -f 3)
# Get last child process (shell, vim, etc)
if [ -n "$PID" ]; then
TREE=$(pstree -lpA $PID | tail -n 1)
PID=$(echo $TREE | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g')
# If we find the working directory, run the command in that directory
if [ -e "/proc/$PID/cwd" ]; then
CWD=$(readlink /proc/$PID/cwd)
fi
fi
if [ -n "$CWD" ]; then
cd $CWD && $CMD
else
$CMD
fi

15
.scripts/i3cmds/td-toggle Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
# If transmission-daemon is running, will ask to kill, else will ask to start.
[ ! -f /usr/bin/transmission-daemon ] && echo "Transmission not installed." && exit
if pgrep -x transmission-da >/dev/null ;
then
yn=$(printf "No\\nYes" | dmenu -i -p "Kill transmission-daemon?")
[ "$yn" = "Yes" ] && killall transmission-da
else
yn=$(printf "No\\nYes" | dmenu -i -p "Start transmission daemon?")
[ "$yn" = "Yes" ] && transmission-daemon
fi
sleep 3 && pkill -RTMIN+7 i3blocks

4
.scripts/i3cmds/tmuxdd Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
# This is the script that i3 runs to either start tmux in
# the dropdown terminal or log into a previous session.
tmux a || tmux

4
.scripts/i3cmds/toggletouchpad Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
# Toggle touchpad. Requires xf86-input-synaptics.
(synclient | grep TouchpadOff.*1 && synclient TouchpadOff=0)>/dev/null && echo "TouchPad reactivated." && exit
synclient TouchpadOff=1 && echo "TouchPad deactivated."

17
.scripts/i3cmds/tutorialvids Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/sh
vidlist="
status bar https://www.youtube.com/watch?v=gKumet6b-WY
feh
i3
mutt https://www.youtube.com/watch?v=2U3vRbF7v5A
ncmpcpp https://www.youtube.com/watch?v=sZIEdI9TS2U
newsboat https://www.youtube.com/watch?v=dUFCRqs822w
ranger https://www.youtube.com/watch?v=L6Vu7WPkoJo
zathura
gpg keys https://www.youtube.com/watch?v=DMGIlj7u7Eo
calcurse https://www.youtube.com/watch?v=hvc-pHjbhdE
urlview https://www.youtube.com/watch?v=IgzpAjFgbCw
vi mode in shell https://www.youtube.com/watch?v=GqoJQft5R2E
"
mpv "$(echo "$vidlist" | grep -P "^$(echo "$vidlist" | grep "https:" | sed 's/\t.*//g' | dmenu -i -p "Learn about what? (ESC to cancel)" -l 5)\\t" | sed 's/.*\t//')"