Lots of bin changes

Jonathan Hodgson 5 years ago
parent 2c617a5b49
commit 121798e075
  1. 2
      bin/.bin/conversion/convert-to-pdf
  2. 29
      bin/.bin/dmenu/password-manager
  3. 3
      bin/.bin/emails/evolution-editor
  4. 47
      bin/.bin/i3/i3exit
  5. 71
      bin/.bin/merrychristmas
  6. 51
      bin/.bin/notifications/datetime
  7. 32
      bin/.bin/printfunction
  8. 29
      bin/.bin/project-management/project-hosts
  9. 2
      bin/.bin/screenlayouts/docked-laptop-left.sh
  10. 24
      bin/.bin/settimer
  11. 9
      bin/.bin/webtest/webtest
  12. 3
      bin/.bin/xkcd

@ -7,6 +7,6 @@ base="${file%.*}"
cd "$dir" || exit
case "$file" in
*\.doc|*\.docx) libreoffice --convert-to pdf "$file" ;;
*\.doc|*\.docx|*\.pptx) libreoffice --convert-to pdf "$file" ;;
*) echo "Don't know how to convert $file"
esac

@ -5,15 +5,27 @@ PASSWORDS="$HOME/.password-store"
function copy_password(){
local password="$1"
local part="${2:-0}"
local sleep_argv0="jh password store sleep on display $DISPLAY"
local before="$(xclip -o -selection clipboard 2>/dev/null | base64)"
pkill -f "^$sleep_argv0" 2>/dev/null && sleep 0.5
local pw=$(pass "$selection" | head -n 1)
local pw=""
case "$part" in
"10"|"otp")
local pw=$(pass otp "$password" | head -n 1)
;;
*)
local pw=$(pass "$password" | head -n 1)
;;
esac
if [ -z "$pw" ]; then
exit 1
fi
echo "$pw" | xclip -selection "primary"
echo "$pw" | xclip -selection "clipboard"
notify-send "Password put on clipboard" "Will be removed in 10 seconds"
notify-send -t 3000 "Password put on clipboard" "Will be removed in 3 seconds"
(
( exec -a "$sleep_argv0" bash <<<"trap 'kill %1' TERM; sleep '10' & wait" )
( exec -a "$sleep_argv0" bash <<<"trap 'kill %1' TERM; sleep '3' & wait" )
echo "$before" | base64 -d | xclip -selection "primary"
echo "$before" | base64 -d | xclip -selection "clipboard"
@ -25,7 +37,12 @@ function copy_password(){
if [ -d "$PASSWORDS" ]; then
cd "$PASSWORDS"
selection=$((echo "NEW";find . -type f -name '*.gpg' | sed 's/.gpg$//' | sed 's/^.\///') | rofi -dmenu -i -l 20)
selection="$1"
ret="${2:-0}"
if [ -z "$selection" ]; then
selection=$((find . -type f -name '*.gpg' | sed 's/.gpg$//' | sed 's/^.\///') | rofi -dmenu -kb-custom-1 "Ctrl-o" -i -l 20)
ret="$?"
fi
if [ -n "$selection" ]; then
if [[ "$selection" == "NEW" ]]; then
dir="$(find . -type d -not -path \*.git\* |rofi -dmenu -p Directory | sed 's/^.\/?//')"
@ -35,9 +52,9 @@ if [ -d "$PASSWORDS" ]; then
name="$(rofi -dmenu -p Name -lines 0)"
# Todo - create new passwords
else
copy_password "$selection"
copy_password "$selection" "$ret"
fi
fi
else
notify-send "$BOOKMARKS doesn't exist"
notify-send "\$PASSWORDS doesn't exist"
fi

@ -0,0 +1,3 @@
#!/usr/bin/env bash
source $HOME/.dotfiles/shells/zsh/current-color-scheme
vim "$@"

@ -1,31 +1,32 @@
#!/bin/sh
lock() {
~/.bin/i3/fadeLockScreen
#i3lock
killall -SIGUSR1 dunst # Pause dunst
~/.bin/i3/fadeLockScreen
killall -SIGUSR2 dunst # Resume dunst
}
case "$1" in
lock)
lock
;;
logout)
i3-msg exit
;;
suspend)
systemctl suspend && lock
;;
hibernate)
systemctl hibernate && lock
;;
reboot)
systemctl reboot
;;
shutdown)
systemctl poweroff
;;
*)
echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
exit 2
lock)
lock
;;
logout)
i3-msg exit
;;
suspend)
systemctl suspend && lock
;;
hibernate)
systemctl hibernate && lock
;;
reboot)
systemctl reboot
;;
shutdown)
systemctl poweroff
;;
*)
echo "Usage: $0 {lock|logout|suspend|hibernate|reboot|shutdown}"
exit 2
esac
exit 0

@ -0,0 +1,71 @@
#!/bin/bash
trap "tput reset; tput cnorm; exit" 2
clear
tput civis
lin=2
col=$(($(tput cols) / 2))
c=$((col-1))
est=$((c-2))
color=0
tput setaf 2; tput bold
# Tree
for ((i=1; i<20; i+=2))
{
tput cup $lin $col
for ((j=1; j<=i; j++))
{
echo -n \*
}
let lin++
let col--
}
tput sgr0; tput setaf 3
# Trunk
for ((i=1; i<=2; i++))
{
tput cup $((lin++)) $c
echo 'mWm'
}
new_year=$(date +'%Y')
let new_year++
tput setaf 1; tput bold
tput cup $lin $((c - 8)); echo MERRY CHRISTMAS IRM
tput cup $((lin + 1)) $((c - 12)); echo And lots of HACKING in $new_year
let c++
k=1
# Lights and decorations
while true; do
for ((i=1; i<=35; i++)) {
# Turn off the lights
[ $k -gt 1 ] && {
tput setaf 2; tput bold
tput cup ${line[$[k-1]$i]} ${column[$[k-1]$i]}; echo \*
unset line[$[k-1]$i]; unset column[$[k-1]$i] # Array cleanup
}
li=$((RANDOM % 9 + 3))
start=$((c-li+2))
co=$((RANDOM % (li-2) * 2 + 1 + start))
tput setaf $color; tput bold # Switch colors
tput cup $li $co
echo o
line[$k$i]=$li
column[$k$i]=$co
color=$(((color+1)%8))
# Flashing text
sh=-1
for l in H A C K I N G
do
tput cup $((lin+1)) $((c+sh))
echo $l
let sh++
sleep 0.01
done
}
k=$((k % 2 + 1))
done
reset

@ -1,3 +1,52 @@
#!/usr/bin/env bash
notify-send "$(date '+%T')" "$(date '+%A %d %B %Y')"
function round() {
echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
}
function drawBar(){
local percent=$1;
for i in {1..10}; do
local boxPercent=$(($i*10))
if [ "$boxPercent" -lt "$percent" ]; then
echo -n "■"
elif [ "$boxPercent" -eq "$percent" ]; then
echo -n "■"
elif [ "$(($boxPercent-10))" -lt "$percent" ]; then
echo -n "▣"
else
echo -n "□"
fi
done
}
function getTimer(){
if [ -e "$HOME/timer" ]; then
local humanDuration=$(head -n 1 "$HOME/timer")
# All these dates are in seconds since the epoch
local duration=$(( $(date -d "now + $humanDuration" '+%s') - $(date '+%s') ))
local startTime=$(stat --format="%Y" "$HOME/timer")
local endTime=$(( $startTime + $duration ))
local currentTime=$(date '+%s')
if [ $endTime -gt $currentTime ]; then
local percentage=$(echo " ( ( $currentTime - $startTime ) * 100 ) / ( $endTime - $startTime ) " | bc )
echo -n "$percentage% "
echo $(drawBar $percentage)
fi
fi
}
time=$(date '+%T')
date=$(date '+%A %d %B %Y')
timer="$(getTimer)"
notify-send "$time" "$date\n$timer$1"

@ -0,0 +1,32 @@
#!/usr/bin/env python
from __future__ import print_function
import pyclbr
import sys
import operator
if __name__ == '__main__':
modname = sys.argv[2]
methname = sys.argv[1]
mod = pyclbr.readmodule(modname)
for clsname, cls in mod.items():
if methname in cls.methods:
print("Method: {} in Class: {}".format(methname, clsname))
methods = sorted(cls.methods.items(), key=operator.itemgetter(1))
clsfile = open(cls.file, 'r')
break
for pair in methods:
name, lineno = pair
if name == methname:
startline = lineno
if methods.index(pair) == methods.index(methods[-1]):
endline = None
else:
endline = methods[methods.index(pair) + 1][1]
break
src = clsfile.readlines()[startline-1:endline-1 if endline is not None else -1]
for srcline in src:
print(srcline, end='')

@ -2,6 +2,10 @@
function print_help(){
echo -e "hosts\t\tManages hosts in the yaml file"
echo -e "\tlist\tLists hosts in the project"
echo -e "\thosts_file\tUpdates the hosts file to reflect the hosts on this project"
echo -e "\tip\tUses fzf to select an IP from the project"
echo -e "\tadd\tAdd an IP address"
}
function listhosts(){
@ -12,7 +16,11 @@ function listhosts(){
exit 1
fi
if [ $(yq -r '.hosts | length ' "$index" ) -gt 0 ]; then
yq -r '.hosts[] | [.name, .ip, .domain, .description] | join(",")' "$index"
yq -r '.hosts[] | [
.ip,
(if ( .domain | type == "array") then .domain | join(",") else .domain end),
.description
] | join(",")' "$index"
else
echo "No hosts in index file"
exit 1
@ -27,7 +35,10 @@ function get_hosts(){
exit 0
fi
if [ $(yq -r '.hosts | length ' "$index" ) -gt 0 ]; then
yq -r '.hosts[]| select(.domain) | [.ip, .domain ] | join(",,")' "$index" | tr ',' '\t'
yq -r '.hosts[]| select(.domain) | [
.ip,
(if ( .domain | type == "array") then .domain | join(",") else .domain end)
] | join(",,")' "$index" | tr ',' '\t'
else
echo ""
exit 0
@ -35,7 +46,6 @@ function get_hosts(){
}
function host_file(){
sed '/# Project specific hosts/,$ d' /etc/hosts > /tmp/newhosts
cat /tmp/newhosts > /etc/hosts
rm /tmp/newhosts
@ -54,20 +64,20 @@ function getip(){
index="$current/index.yaml"
case "$1" in
--fzf)
ip=$( listhosts | fzf --no-preview | cut -d',' -f2)
ip=$( listhosts | fzf --no-preview | cut -d',' -f1)
;;
--dmenu)
ip=$( listhosts | dmenu | cut -d',' -f2)
ip=$( listhosts | dmenu | cut -d',' -f1)
echo "$ip" | xclip -selection primary
echo "$ip" | xclip -selection clipboard
;;
--rofi)
ip=$( listhosts | rofi -dmenu | cut -d',' -f2)
ip=$( listhosts | rofi -dmenu | cut -d',' -f1)
echo "$ip" | xclip -selection primary
echo "$ip" | xclip -selection clipboard
;;
*)
ip=$( listhosts | fzf --no-preview | cut -d',' -f2)
ip=$( listhosts | fzf --no-preview | cut -d',' -f1)
;;
esac
echo $ip
@ -76,8 +86,6 @@ function getip(){
function addip(){
local current="$(project current --path)"
index="$current/index.yaml"
echo -n "Name: "
read name < /dev/tty
echo -n "Domain: "
read domain < /dev/tty
echo -n "IP: "
@ -85,9 +93,6 @@ function addip(){
echo -n "Description: "
read description < /dev/tty
local host='{}'
if [ -n "$name" ]; then
host="$(echo $host | jq ".name=\"$name\"" )"
fi
if [ -n "$domain" ]; then
host="$(echo $host | jq ".domain=\"$domain\"" )"
fi

@ -0,0 +1,2 @@
#!/bin/sh
xrandr --output eDP-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal --output DP-1 --off --output HDMI-1 --off --output DP-2 --off --output HDMI-2 --mode 1920x1080 --pos 1920x0 --rotate normal

@ -0,0 +1,24 @@
#!/usr/bin/env bash
echo "$@" > "$HOME/timer"
humanDuration=$(head -n 1 "$HOME/timer")
# All these dates are in seconds since the epoch
duration=$(( $(date -d "now + $humanDuration" '+%s') - $(date '+%s') ))
# Display date time notification when half way
( sleep $(( duration / 2 ))
datetime
) & disown
# Display date time notification when 90% done
( sleep $(( (duration * 9) / 10 ))
datetime
) & disown
# Display date time notification when half way
( sleep $duration
datetime "Finished"
) & disown

@ -0,0 +1,9 @@
#!/usr/bin/env bash
domain="$1"
if [ -z "$domain" ];
echo "You need to give a domain or ip address"
fi
if

@ -10,4 +10,5 @@ else
json=$(curl https://xkcd.com/$comic/info.0.json 2> /dev/null)
fi
echo $json | /usr/bin/jq -C
echo $json | /usr/bin/jq ".img" | xargs sxiv
echo $json | /usr/bin/jq ".img" | xargs curl -s -o /tmp/xkcd
sxiv /tmp/xkcd

Loading…
Cancel
Save