Reorganize files for easier restoring via stow, more familiar file structure.

This commit is contained in:
2019-10-22 16:04:37 -04:00
parent aaf05c5231
commit b24321d392
49 changed files with 42 additions and 33 deletions

86
.local/bin/i3scripts/i3empty.py Executable file
View File

@@ -0,0 +1,86 @@
#!/bin/env python3
import sys
import re
import json
from subprocess import run, PIPE
import argparse
def get_ws():
return json.loads(run('i3-msg -t get_workspaces'.split(), stdout=PIPE).stdout)
def to_empty(current=None, strict=False, right=True, move=False, wrap=True, min_num=1):
"""Move to nearest empty numbered workspace"""
if current is None:
current = [w for w in get_ws() if w['focused']][0]
numbered = re.compile('^\d+$' if strict else '^\d+|(\d+:.*)$')
ns = {w['num'] for w in get_ws() if numbered.match(w['name']) != None and
(not strict or w['name'] == str(w['num']))}
if numbered.match(current['name']) is None:
# If current workspace is unnumbered, pick rightmost or leftmost
if len(ns) == 0:
new_ix = min_num
else:
new_ix = min(ns) - 1 if right else max(ns) + 1
else:
# Find numbered workspace nearest to current
new_ix = current['num']
while new_ix in ns:
new_ix += 1 if right else -1
# Wrap around
if new_ix < min_num:
if wrap:
new_ix = max(ns) + 1
else:
return
if move:
s = 'i3-msg move container to workspace {0}; workspace {0}'.format(new_ix)
else:
s = 'i3-msg workspace ' + str(new_ix)
print(s)
run(s.split())
def to_empty_near(num, relative=False, **kwargs):
"""Move to empty numbered workspace nearest to workspace 'num'"""
if relative:
if 0 <= num < len(get_ws()):
current = get_ws()[num]
else:
return
else:
ns = [w for w in get_ws() if w['num'] == num]
current = ns[0] if len(ns) > 0 else {'num': num, 'name': str(num)}
to_empty(current, **kwargs)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Switch to an empty numbered workspace.')
parser.add_argument('direction', type=str, nargs='?', default='next',
help='either next (default) or prev')
parser.add_argument('number', type=int, nargs='?',
help='workspace to start searching from (default: current)')
parser.add_argument('-r', '--relative', dest='rel', action='store_true',
help='use workspace indices, not numbers (default: no)')
parser.add_argument('-w', '--nowrap', dest='wrap', action='store_false',
help='if at edge, wrap around to other edge (default: yes)')
parser.add_argument('-s', '--nostrict', dest='strict', action='store_false',
help='numbered workspaces have a numeric name (default: yes)')
parser.add_argument('-m', '--move', dest='move', action='store_true',
help='move container to new workspace (default: no)')
args = parser.parse_args()
kwargs = {'right': args.direction.lower().strip() == 'next',
'wrap': args.wrap, 'strict': args.strict, 'move': args.move}
if type(args.number) is int:
to_empty_near(args.number, relative=args.rel, **kwargs)
else:
to_empty(**kwargs)

View File

@@ -0,0 +1,63 @@
#!/bin/sh
# shellcheck disable=SC2016,SC2059
KEYBOARD_ID="Corsair Corsair STRAFE Gaming Keyboard"
# cpm: characters per minute
# wpm: words per minute (1 word = 5 characters)
METRIC=wpm
FORMAT=" %d $METRIC"
INTERVAL=2
# If you have a keyboard layout that is not listed here yet, create a condition
# yourself. $3 is the key index. Use `xinput test "AT Translated Set 2 keyboard"`
# to see key codes in real time. Be sure to open a pull request for your
# layout's condition!
LAYOUT=qwerty
case "$LAYOUT" in
qwerty) CONDITION='($3 >= 10 && $3 <= 19) || ($3 >= 24 && $3 <= 33) || ($3 >= 37 && $3 <= 53) || ($3 >= 52 && $3 <= 58)'; ;;
azerty) CONDITION='($3 >= 10 && $3 <= 19) || ($3 >= 24 && $3 <= 33) || ($3 >= 37 && $3 <= 54) || ($3 >= 52 && $3 <= 57)'; ;;
qwertz) CONDITION='($3 >= 10 && $3 <= 20) || ($3 >= 24 && $3 <= 34) || ($3 == 36) || ($3 >= 38 && $3 <= 48) || ($3 >= 52 && $3 <= 58)'; ;;
dontcare) CONDITION='1'; ;; # Just register all key presses, not only letters and numbers
*) echo "Unsupported layout \"$LAYOUT\""; exit 1; ;;
esac
# We have to account for the fact we're not listening a whole minute
multiply_by=60
divide_by=$INTERVAL
case "$METRIC" in
wpm) divide_by=$((divide_by * 5)); ;;
cpm) ;;
*) echo "Unsupported metric \"$METRIC\""; exit 1; ;;
esac
hackspeed_cache="$(mktemp -p '' hackspeed_cache.XXXXX)"
trap 'rm "$hackspeed_cache"' EXIT
# Write a dot to our cache for each key press
printf '' > "$hackspeed_cache"
xinput test "$KEYBOARD_ID" | \
stdbuf -o0 awk '$1 == "key" && $2 == "press" && ('"$CONDITION"') {printf "."}' >> "$hackspeed_cache" &
while true; do
# Ask the kernel how big the file is with the command `stat`. The number we
# get is the file size in bytes, which equals the amount of dots the file
# contains, and hence how much keys were pressed since the file was last
# cleared.
lines=$(stat --format %s "$hackspeed_cache")
# Truncate the cache file so that in the next iteration, we count only new
# keypresses
printf '' > "$hackspeed_cache"
# The shell only does integer operations, so make sure to first multiply and
# then divide
value=$((lines * multiply_by / divide_by))
printf "$FORMAT\\n" "$value"
sleep $INTERVAL
done

25
.local/bin/i3scripts/info-idle Executable file
View File

@@ -0,0 +1,25 @@
#!/bin/bash
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
## ##
## A script to track system idle time within a polybar menu ##
###############################################################################
# info-idle.sh
METRIC=sec
FORMAT=" %d $METRIC"
INTERVAL=2
case "$METRIC" in
min) DIVIDE_BY=$((1000 * 60)); ;;
sec) DIVIDE_BY=1000; ;;
msec) DIVIDE_BY=1 ;;
*) echo "Unsupported metric \"$METRIC\""; exit 1; ;;
esac
while true; do
VALUE=$(($(xprintidle)/ DIVIDE_BY))
printf "$FORMAT\\n" "$VALUE"
sleep $INTERVAL
done

View File

@@ -0,0 +1,41 @@
#!/bin/sh
BAR_HEIGHT=22 # polybar height
BORDER_SIZE=1 # border size from your wm settings
YAD_WIDTH=222 # 222 is minimum possible value
YAD_HEIGHT=193 # 193 is minimum possible value
DATE="$(TZ=UTC date +"%a %d %H:%M")"
case "$1" in
--popup)
if [ "$(xdotool getwindowfocus getwindowname)" = "yad-calendar" ]; then
exit 0
fi
eval "$(xdotool getmouselocation --shell)"
eval "$(xdotool getdisplaygeometry --shell)"
# X
if [ "$((X + YAD_WIDTH / 2 + BORDER_SIZE))" -gt "$WIDTH" ]; then #Right side
: $((pos_x = WIDTH - YAD_WIDTH - BORDER_SIZE))
elif [ "$((X - YAD_WIDTH / 2 - BORDER_SIZE))" -lt 0 ]; then #Left side
: $((pos_x = BORDER_SIZE))
else #Center
: $((pos_x = X - YAD_WIDTH / 2))
fi
# Y
if [ "$Y" -gt "$((HEIGHT / 2))" ]; then #Bottom
: $((pos_y = HEIGHT - YAD_HEIGHT - BAR_HEIGHT - BORDER_SIZE))
else #Top
: $((pos_y = BAR_HEIGHT + BORDER_SIZE))
fi
yad --calendar --undecorated --fixed --close-on-unfocus --no-buttons \
--width=$YAD_WIDTH --height=$YAD_HEIGHT --posx=$pos_x --posy=$pos_y \
--title="yad-calendar" --borders=0 >/dev/null &
;;
*)
echo "$DATE"
;;
esac

View File

@@ -0,0 +1,6 @@
#!/bin/bash
conky -c $HOME/.config/conky/shortcuts_green &&
conky -c $HOME/.config/conky/sysinfo_green &&
exit 0

96
.local/bin/i3scripts/weathermap Executable file
View File

@@ -0,0 +1,96 @@
#!/bin/sh
get_icon() {
case $1 in
01d) icon="滛";; # Sun clear
01n) icon="";; # Moon clear
02d) icon="";; # Sun cloudy
02n) icon="";; # Moon cloudy
03*) icon="";; # Cloud
04*) icon="";; # Clouds
09d) icon="";; # Day, cloud, rain, wind
09n) icon="";; # Night, cloud, rain, wind
10d) icon="";; # Day rain
10n) icon="";; # Night rain
11d) icon="";; # Day, rain, lightning
11n) icon="";; # Night, rain, lightning
13d) icon="";; # Day, snow
13n) icon="";; # Night, snow
50d) icon="";; # Day, fog
50n) icon="";; # Night, fog
*) icon=""; # Sun clear, default icon
esac
echo $icon
}
get_duration() {
osname=$(uname -s)
case $osname in
*BSD) date -r "$1" -u +%H:%M;;
*) date --date="@$1" -u +%H:%M;;
esac
}
KEY="3fbb0282dfd1ba8295bcb93b329fd152"
CITY="5149222"
UNITS="imperial"
SYMBOL="°"
API="https://api.openweathermap.org/data/2.5"
if [ -n "$CITY" ]; then
if [ "$CITY" -eq "$CITY" ] 2>/dev/null; then
CITY_PARAM="id=$CITY"
else
CITY_PARAM="q=$CITY"
fi
current=$(curl -sf "$API/weather?appid=$KEY&$CITY_PARAM&units=$UNITS")
forecast=$(curl -sf "$API/forecast?appid=$KEY&$CITY_PARAM&units=$UNITS&cnt=1")
else
location=$(curl -sf https://location.services.mozilla.com/v1/geolocate?key=geoclue)
if [ -n "$location" ]; then
location_lat="$(echo "$location" | jq '.location.lat')"
location_lon="$(echo "$location" | jq '.location.lng')"
current=$(curl -sf "$API/weather?appid=$KEY&lat=$location_lat&lon=$location_lon&units=$UNITS")
forecast=$(curl -sf "$API/forecast?appid=$KEY&lat=$location_lat&lon=$location_lon&units=$UNITS&cnt=1")
fi
fi
if [ -n "$current" ] && [ -n "$forecast" ]; then
current_temp=$(echo "$current" | jq ".main.temp" | cut -d "." -f 1)
current_icon=$(echo "$current" | jq -r ".weather[0].icon")
forecast_temp=$(echo "$forecast" | jq ".list[].main.temp" | cut -d "." -f 1)
forecast_icon=$(echo "$forecast" | jq -r ".list[].weather[0].icon")
if [ "$current_temp" -gt "$forecast_temp" ]; then
trend="" # Arrow, down-right slant
elif [ "$forecast_temp" -gt "$current_temp" ]; then
trend="" # Arrow, up-right slant
else
trend="" # Arrow, left-to-right
fi
sun_rise=$(echo "$current" | jq ".sys.sunrise")
sun_set=$(echo "$current" | jq ".sys.sunset")
now=$(date +%s)
if [ "$sun_rise" -gt "$now" ]; then
daytime=" $(get_duration "$((sun_rise-now))")" # Sun rise
elif [ "$sun_set" -gt "$now" ]; then
daytime=" $(get_duration "$((sun_set-now))")" # Sun set
else
daytime=" $(get_duration "$((sun_rise-now))")" # Unknown
fi
echo "$(get_icon "$current_icon") $current_temp$SYMBOL $trend $(get_icon "$forecast_icon") $forecast_temp$SYMBOL $daytime"
fi

23
.local/bin/i3scripts/xoffee Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
## ##
## A script to toggle and notify xautolock via polybar menus ##
###############################################################################
# xoffee.sh
if [ $# -ne 1 ]; then
echo "Incorrect number of arguments provided"
exit 1
fi
if [ "$1" = "enable" ]; then
xautolock -disable
notify-send "Caffeine enabled"
elif [ "$1" = "disable" ]; then
xautolock -enable
notify-send "Caffeine disabled"
else
notify-send "Error: Incorrect arg for xoffee script"
exit 1
fi