commit dae2e4e5e920ae77d0b6c81f6429596c52390a46
parent 396ee335fee809be0f0a091b8d14727887750e9f
Author: josuah <mail@josuah.net>
Date: Sat, 12 Nov 2016 13:25:02 -0500
Thanks for this lightsaber
Diffstat:
A | bin/lightsaber | | | 172 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | bin/lsync | | | 28 | ++++++++++++++++++++++++++++ |
M | bin/piano | | | 8 | ++++---- |
3 files changed, 204 insertions(+), 4 deletions(-)
diff --git a/bin/lightsaber b/bin/lightsaber
@@ -0,0 +1,172 @@
+# Author: L. S., a long time ago
+
+# Thank you to jansen.price@gmail.com for the original idea.
+
+help()
+{
+ printf 'Usage: %s COLOR WIDTH
+
+COLOR
+ ' "${0##*/}"
+
+ for i in $(seq 7)
+ do
+ printf '\033[3%sm%s\033[0m ' "$i" "$i"
+ done
+
+ printf '
+
+WIDTH
+ Integer from 0 to 100
+
+CONTROLS
+ Enter to start
+
+ Ctrl + C to stop
+'
+ exit 1
+}
+
+
+#
+# This clears the screen, print the handle set cursor position at the middle of
+# the blade and saves it
+#
+print_handle()
+{
+ local h1='._________,_'
+ local h2='\033[47;30;1mIIIIIIIIIII\033[0mH'
+ local h3='""""""""\033[31m'"$1"'\033[0m""^'
+ local width=12
+
+ # reset the screen: handle is first thing we draw
+ printf '\033[2J\033[10;30H'
+
+ for line in "$h1" "$h2" "$h3"
+ do
+ printf "$line\033[0m\v\033[%sD" "$width"
+ done
+
+ printf '\033[%sC\033[2A\033[s' "$width"
+}
+
+
+print_blade()
+{
+ local color="$1" length="$2"
+ local b1=' '
+ local b2='_' # foreground and background with color and bold foreground
+ local b3=" "
+
+ for i in $(seq "$length")
+ do
+ sleep 0.003
+ printf '\033[1;4%s;3%sm%s\033[0m' \
+ "$color" "$color" "$b2"
+ done
+
+ # Put cursor at the beginning of the blade
+ printf '\033[%sD' "$i"
+}
+
+
+wait_button()
+{
+ printf ' '
+ read
+ printf '\033[u'
+
+ # reset the previous state
+ print_handle '-'
+}
+
+blink_blade()
+{
+ local color="$1" length="$2"
+ local top top_char='.'
+ local bot bot_char="'"
+ local end1="'" end2='.'
+
+ # set color
+ printf '\033[3%sm' "$color"
+
+ # save cursor location
+ printf '\033\033[s'
+
+ # generate the blinks from the blink chars
+ for i in $(seq "$((length / 2))")
+ do
+ top="$top_char $top"
+ bot="$bot_char $bot"
+ done
+
+ # Blink the blade
+ while true
+ do
+ printf '\033[%sC%s\033[u' "$length" "$end1"
+ printf '\033[A\033[K%s%s\033[u' '' "$top"
+ printf '\033[B\033[K%s%s\033[u' '' "$bot"
+
+ printf '\033[%sC%s\033[u' "$length" "$end2"
+ printf '\033[A\033[K%s%s\033[u' ' ' "$top"
+ printf '\033[B\033[K%s%s\033[u' ' ' "$bot"
+
+ done
+}
+
+
+close_saber()
+{
+ local length="$1" button_position="$2"
+
+ # ensure we are at the right position
+ printf '\033[u'
+
+ for i in $(seq "$(($length + 3))" -1 1)
+ do
+ printf '\033[%sC\033[A' "$i"
+ for j in 1 2 3
+ do
+ printf ' \v\033[D'
+ done
+ printf '\033[u'
+
+ sleep 0.001
+ done
+
+ printf ' \033[0m'
+
+ print_handle '='
+
+ printf '\n\n\n'
+ exit 0
+}
+
+
+main()
+{
+ local color="${1:-1}" length="${2:-50}"
+
+ case "$1" in
+ [1-7] | '' ) : ;;
+ * ) help ;;
+ esac
+
+ case "$2" in
+ [0-9] | [0-9][0-9] | 1[0-9][0-9] | '' ) : ;;
+ * ) help ;;
+ esac
+
+ # close the saber while script stops
+ trap "close_saber '$length' 4" INT
+
+ {
+ print_handle '='
+ wait_button 4
+ print_blade "$color" "$length"
+ blink_blade "$color" "$length"
+ } 2>/dev/null
+}
+
+
+main $@
diff --git a/bin/lsync b/bin/lsync
@@ -0,0 +1,28 @@
+lcp()
+{
+ printf '%s' "cp \"$1"\ "\$2"\"
+}
+
+
+main()
+{
+ local dir1="$1" dir2="$2"
+ local path
+
+ for dir in "$dir1" "$dir2"
+ do
+ (
+ cd "$dir1"
+ find . -type f | xargs md5sum
+ )
+ done | sort | uniq -u | while read -r hash file
+ do
+ printf '%s %s\n' "$hash" "$file"
+ done | sort | uniq -w 32 -u | while read -r hash file
+ do
+ printf '%s %s\n' "$hash" "$file"
+ done
+}
+
+
+main $@
diff --git a/bin/piano b/bin/piano
@@ -28,7 +28,7 @@ BEGIN {
# Bottom two rows Top two rows
qwerty = "zsxdcvgbhnjm,l.;/" "q2w3er5t6y7ui9o0p[=]"; # Without shift
- QWERTY = "ZSXDCVGBHNJM<L>:/" "Q@W#ER5T^Y&UI(O)P{+}"; # With shift
+ QWERTY = "ZSXDCVGBHNJM<L>:/" "Q@W#ER%T^Y&UI(O)P{+}"; # With shift
qwerty = qwerty QWERTY;
# DVORAK
@@ -47,8 +47,8 @@ BEGIN {
# |______|______|______|_______________________________|______|_____|_____|
# Bottom two rows Top two rows
- dvorak = ";oqejkixdbhmwnvsz" "'2,3.p5y6f7gc9r0l/]="; # Without shift
- DVORAK = ":OQEJKIXDBHMWNVSZ" "\"@<#>P%Y^F&GC(R)L?}+"; # With shift
+ dvorak = ";oqejkixdbhmwnvsz" "'2,3.p5y6f7gc9r0l/]="; # Without shift
+ DVORAK = ":OQEJKIXDBHMWNVSZ" "\"@<#>P%Y^F&GC(R)L?}+"; # With shift
dvorak = dvorak DVORAK;
layout = dvorak;
@@ -133,7 +133,7 @@ BEGIN {
} else if (key == " ") {
duration = duration * 2;
} else if (note = frequencies[index(layout, key)]) {
- system("beep -l " duration * 100 " -f " note);
+ system("beep -l " duration * 50 " -f " note);
duration = 1;
}
}