aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkatherine <shmibs@shmibbles.me>2017-02-19 03:47:19 -0700
committerkatherine <shmibs@shmibbles.me>2017-02-19 03:47:19 -0700
commit4cd93b09b3a179515630114078739564a35af38d (patch)
tree9d4b873cca07f62f457acd82df0c433bd2af1535
parent01cc1fd9f8d3484451fb33dc06d3eb76622dd7e0 (diff)
downloaddotfiles-4cd93b09b3a179515630114078739564a35af38d.tar.gz
move remaining funcs from .zshrc
everything should be modular now also, cleaned up make-gif to properly parse arguments and check things
-rw-r--r--.config/init/funcreqs/b2h2
-rw-r--r--.config/init/funcreqs/make-gif2
-rw-r--r--.config/init/funcreqs/mpd-filetypes2
-rw-r--r--.config/init/funcreqs/spam2
-rw-r--r--.config/init/funcreqs/ssh-scrot2
-rwxr-xr-x.config/init/funcs/b2h14
-rwxr-xr-x.config/init/funcs/make-gif97
-rwxr-xr-x.config/init/funcs/mpd-filetypes99
-rwxr-xr-x.config/init/funcs/spam25
-rwxr-xr-x.config/init/funcs/ssh-scrot45
-rw-r--r--.zprofile4
-rw-r--r--.zshrc17
-rw-r--r--.zshrc-linux27
-rw-r--r--.zshrc-linux-desktop387
14 files changed, 309 insertions, 416 deletions
diff --git a/.config/init/funcreqs/b2h b/.config/init/funcreqs/b2h
new file mode 100644
index 0000000..b3cc909
--- /dev/null
+++ b/.config/init/funcreqs/b2h
@@ -0,0 +1,2 @@
+func_init_prereqs=(ffmpeg)
+func_init_checks=()
diff --git a/.config/init/funcreqs/make-gif b/.config/init/funcreqs/make-gif
new file mode 100644
index 0000000..e5d0a9e
--- /dev/null
+++ b/.config/init/funcreqs/make-gif
@@ -0,0 +1,2 @@
+func_init_prereqs=(grep bc)
+func_init_checks=()
diff --git a/.config/init/funcreqs/mpd-filetypes b/.config/init/funcreqs/mpd-filetypes
new file mode 100644
index 0000000..4ddbbd7
--- /dev/null
+++ b/.config/init/funcreqs/mpd-filetypes
@@ -0,0 +1,2 @@
+func_init_prereqs=(mpd)
+func_init_checks=("stat $HOME/music")
diff --git a/.config/init/funcreqs/spam b/.config/init/funcreqs/spam
new file mode 100644
index 0000000..8365431
--- /dev/null
+++ b/.config/init/funcreqs/spam
@@ -0,0 +1,2 @@
+func_init_prereqs=()
+func_init_checks=()
diff --git a/.config/init/funcreqs/ssh-scrot b/.config/init/funcreqs/ssh-scrot
new file mode 100644
index 0000000..ba9e7fb
--- /dev/null
+++ b/.config/init/funcreqs/ssh-scrot
@@ -0,0 +1,2 @@
+func_init_prereqs=(ssh scrot convert)
+func_init_checks=()
diff --git a/.config/init/funcs/b2h b/.config/init/funcs/b2h
new file mode 100755
index 0000000..3a8d15a
--- /dev/null
+++ b/.config/init/funcs/b2h
@@ -0,0 +1,14 @@
+#!/usr/bin/env zsh
+# convert bits to human-readable value
+
+local suffixes=( 'B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y' )
+local sindex=1
+local val=$1
+[[ -z $(echo $1 | grep "^[0-9]*$") ]] && read val
+
+while [[ $(echo $val / 1024 | bc) -ne 0 ]]; do
+ val=$(echo "scale=2; $val / 1024" | bc)
+ let sindex=sindex+1
+done
+
+echo "${val}${suffixes[$sindex]}"
diff --git a/.config/init/funcs/make-gif b/.config/init/funcs/make-gif
new file mode 100755
index 0000000..7b3145c
--- /dev/null
+++ b/.config/init/funcs/make-gif
@@ -0,0 +1,97 @@
+#!/usr/bin/env zsh
+# export a clip from a video as a gif
+
+local callstr="$0"
+
+usage() {
+ [[ "$1" != "" ]] && echo -e "\e[1;31merror:\e[0m $1\n"
+ echo "Usage: $callstr [OPTIONS...] <infile> <outfile>"
+ echo ""
+ echo "description option default val"
+ echo "start time -s <time> 00:00:00"
+ echo "length in seconds -t <int> full length"
+ echo "gif fps -f <int> 10"
+ echo "gif pixel width -w <int> 480"
+ echo "use subtitles -b"
+ echo "print this help -h"
+ exit 1
+}
+
+local start="00:00:00"
+local length=""
+local fps=10
+local width=480
+local subs=""
+
+local timepat='^(([0-9][0-9]:){1,2}[0-9][0-9]|[0-9]+)$'
+local intpat='^[0-9][0-9]*$'
+
+local t=""
+
+while getopts s:t:f:w:bh opt; do
+ case "$opt" in
+ s)
+ [[ ! $(echo $OPTARG | grep -oE "$timepat") ]] \
+ && usage "malformed start timestamp"
+ start="$OPTARG"
+ ;;
+ t)
+ [[ ! $(echo $OPTARG | grep -oE "$intpat") ]] \
+ && usage "length must be an integer"
+ length=$OPTARG
+ t="-t"
+ ;;
+ f)
+ [[ ! $(echo $OPTARG | grep -oE "$intpat") ]] \
+ && usage "start time must be an integer"
+ fps=$OPTARG
+ ;;
+ w)
+ [[ ! $(echo $OPTARG | grep -oE "$intpat") ]] \
+ && usage "fps must be an integer"
+ width=$OPTARG
+ ;;
+ b) subs=true ;;
+ h) usage ;;
+ [?]) usage ;;
+ esac
+done
+shift $OPTIND-1
+
+[[ ${#@} -gt 2 ]] && usage "trailing arguments detected"
+
+[[ ${#@} -lt 2 ]] && usage "no output file specified"
+
+[[ "${2:e}" != "gif" ]] && usage "output file must have a .gif file extension"
+
+[[ ! -f "$1" ]] && usage "input file not found"
+
+
+rm -f make-gif-palette.png
+rm -f make-gif-in
+
+ln -s "$1" make-gif-in
+
+if [[ $subs ]]; then
+ echo "pass 1..."
+ ffmpeg -loglevel 16 -y -ss $start $t $length -i "$1" -copyts \
+ -vf "subtitles=make-gif-in,fps=$fps,scale=$width:-1:flags=lanczos,palettegen" \
+ make-gif-palette.png
+ [[ $? -eq 0 ]] && echo "pass 2..." && ffmpeg -loglevel 24 \
+ -ss $start $t $length -i "$1" -i make-gif-palette.png \
+ -copyts -filter_complex \
+ "subtitles=make-gif-in,fps=$fps,scale=$width:-1:flags=lanczos[x];[x][1:v]paletteuse" \
+ out.gif
+else
+ echo "pass 1..."
+ ffmpeg -loglevel 16 -y -ss "$start" $t $length -i "$1" \
+ -vf "fps=$fps,scale=$width:-1:flags=lanczos,palettegen" \
+ make-gif-palette.png
+ [[ $? -eq 0 ]] && echo "pass 2..." && ffmpeg -loglevel 24 \
+ -ss $start $t $length -i "$1" -i make-gif-palette.png -filter_complex \
+ "fps=$fps,scale=$width:-1:flags=lanczos[x];[x][1:v]paletteuse" \
+ out.gif
+fi
+
+rm -f make-gif-palette.png
+rm -f make-gif-in
diff --git a/.config/init/funcs/mpd-filetypes b/.config/init/funcs/mpd-filetypes
new file mode 100755
index 0000000..0bc93d2
--- /dev/null
+++ b/.config/init/funcs/mpd-filetypes
@@ -0,0 +1,99 @@
+#!/usr/bin/env zsh
+# list stats about mpd library file types, to motivate me
+# to do better!
+
+local pattern
+
+# if args exist, read them as file extensions in a pattern
+if
+if [[ ! -z "$@" ]]; then
+ pattern=$(echo "$@" | sed -e 's/\s/|/g' -e 's/\(.*\)/(\1)/')
+else
+# else hackily yoink recognised types from mpd --version
+ pattern=$(mpd --version \
+ | sed -n '1h; 1!H; ${g; s/.*Decoders plugins:\(.*\)Output.*/\1/g; p}' \
+ | sed -e 's/.*\]//' | tr -d '\n' \
+ | sed -e 's/^ //' -e 's/\s/|/g' -e 's/\(.*\)/(\1)/')
+fi
+
+# find file counts
+local i=1
+local total=0
+local totalstr='total'
+local counts=()
+local types=()
+find ~/music -type f -regextype posix-extended \
+ -regex ".*\.$pattern" | grep -oE "\.$pattern$" \
+ | sort | uniq -c | sed -e 's/^\s*\([0-9]* \)\./\1/' | \
+while read -A line; do
+ counts[$i]=${line[1]}
+ types[$i]=${line[2]}
+ total=$(( $total + ${line[1]} ))
+ i=$(( $i + 1 ))
+done
+
+# calculate percentages
+local twidth=0
+local cwidth=0
+local percentages=()
+for i in {1..${#types}}; do
+ percentages[$i]="%$(calc -p \
+ "a=${counts[$i]} * 100 / $total; round(a, 5-digits(a), 16)" \
+ | tr -d '~')"
+
+done
+
+types=( 'type' "${types[@]}" 'total' )
+counts=( 'count' "${counts[@]}" $total )
+percentages=( 'percent' "${percentages[@]}" ' ')
+
+# calculate padding widths
+for i in {1..${#types}}; do
+ if [[ ${#types[$i]} -gt $twidth ]]; then
+ twidth=${#types[$i]}
+ fi
+
+ if [[ ${#counts[$i]} -gt $cwidth ]]; then
+ cwidth=${#counts[$i]}
+ fi
+done
+
+
+# print results
+local linelen=$(( $twidth + $cwidth + 13 ))
+local j
+echo -n "┌"
+for (( j=0; j < $linelen; j++ )); do
+ echo -n "─"
+done
+echo "┐"
+
+for i in {1..${#types}}; do
+ if [[ $i -eq 2 || $i -eq ${#types} ]]; then
+ echo -n "├"
+ for (( j=0; j < $linelen; j++ )); do
+ echo -n "─"
+ done
+ echo "┤"
+ fi
+
+ if [[ $i -eq 1 ]]; then
+ printf "│ %${twidth}s " "${types[$i]}"
+ else
+ printf "│ %${twidth}s: " "${types[$i]}"
+ fi
+
+ printf "%${cwidth}s" "${counts[$i]}"
+
+ if [[ $i -eq 1 || $i -eq ${#types} ]]; then
+ printf " %-7s │\n" "${percentages[$i]}"
+ else
+ printf ", %-7s │\n" "${percentages[$i]}"
+ fi
+done
+
+echo -n "└"
+for (( j=0; j < $linelen; j++ )); do
+ echo -n "─"
+done
+echo "┘"
diff --git a/.config/init/funcs/spam b/.config/init/funcs/spam
new file mode 100755
index 0000000..77fa872
--- /dev/null
+++ b/.config/init/funcs/spam
@@ -0,0 +1,25 @@
+#!/usr/bin/env zsh
+# um...
+
+if [[ $# -eq 0 ]]; then
+ local spam="┐(笑)_(笑)┌"
+else
+ local spam="$@"
+fi
+
+
+while true; do
+ echo -en "\e[$((RANDOM%2));$((RANDOM%8+30))m"
+
+ for i in {1..${#spam}}; do
+ if [[ $((RANDOM%2)) -eq 1 ]]; then
+ echo -n $spam[$i] | tr '[:lower:]' '[:upper:]'
+ else
+ echo -n $spam[$i]
+ fi
+ done
+
+ for i in {1..$((RANDOM%20))}; do
+ echo -n " "
+ done
+done
diff --git a/.config/init/funcs/ssh-scrot b/.config/init/funcs/ssh-scrot
new file mode 100755
index 0000000..1e6a90c
--- /dev/null
+++ b/.config/init/funcs/ssh-scrot
@@ -0,0 +1,45 @@
+#!/usr/bin/env zsh
+# take a screenshot, upload to /img/scrot, and update current symlink
+
+archey3
+
+local name
+if [[ "$1" != "" ]]; then
+ name=$1
+else
+ echo -n "name: "
+ read name
+fi
+
+local date=$(date +'%Y-%m-%d')
+
+local folder="http/img/scrot"
+ssh shmibbles.me "mkdir -p $folder/$date"
+
+if [[ "${?#0}" != "" ]]; then
+ return 1
+fi
+
+ssh shmibbles.me "cd $folder; rm current 2>/dev/null; ln -s $date current"
+
+for i in {3..1}; do
+ echo -n "$i "
+ sleep 1
+done
+
+echo 'cheese!'
+sleep .1
+
+scrot /tmp/$name.png
+convert -scale 250x /tmp/$name.png /tmp/${name}_small.png
+
+scp /tmp/$name.png /tmp/${name}_small.png shmibbles.me:http/img/scrot/$date
+
+echo "https://shmibbles.me/img/scrot/$date/$name.png" | tr -d '\n' | xclip -i -selection clipboard
+echo "https://shmibbles.me/img/scrot/$date/$name.png" | tr -d '\n' | xclip -i -selection primary
+echo "https://shmibbles.me/img/scrot/$date/${name}_small.png" | tr -d '\n' | xclip -i -selection clipboard
+echo "https://shmibbles.me/img/scrot/$date/${name}_small.png" | tr -d '\n' | xclip -i -selection primary
+
+echo 'sent!'
+
+rm /tmp/$name.png /tmp/${name}_small.png
diff --git a/.zprofile b/.zprofile
index 6f4e509..5ae8c18 100644
--- a/.zprofile
+++ b/.zprofile
@@ -38,8 +38,10 @@ if [[ -d ~/.config/init/funcs/ && -d ~/.config/init/funcreqs ]]; then
for f in $HOME/.config/init/funcreqs/*; do
source "$f"
func_init_checkreq $func_init_prereqs , $func_init_checks
- [[ $? -eq 0 ]] && \
+ if [[ $? -eq 0 ]] then
+ chmod +x $HOME/.config/init/funcs/${f:t}
ln -s $HOME/.config/init/funcs/${f:t} /tmp/funcs/${f:t}
+ fi
done
fi
diff --git a/.zshrc b/.zshrc
index 8426fab..41a9c2a 100644
--- a/.zshrc
+++ b/.zshrc
@@ -26,7 +26,7 @@ unsetopt beep
if [[ "$TERM" == "rxvt-unicode-256color" ]]; then
precmd() {
- print -Pn "\e]0;zsh: %(1j,%j job%(2j|s|); ,)%~\a"
+ print -Pn "\e]0;zsh:%(1j,%j job%(2j|s|); ,)%~\a"
}
preexec() {
@@ -134,12 +134,27 @@ fi
[[ "$(whence aiksaurus)" != "" ]] && alias thesaurus='aiksaurus'
[[ "$(whence ag)" != "" ]] && alias ag='ag --color-match "1;34"'
[[ "$(whence latex)" != "" ]] && alias latex='latex -output-format=pdf'
+[[ "$(whence startx)" != "" ]] && alias sx='startx'
if [[ "$(whence udevil)" != "" ]] then
alias vmount='udevil mount'
alias vumount='udevil umount'
fi
+################## FUNCTIONS ##################
+
+# ignore non-tracked files
+if [[ "$(whence git)" != "" ]] then
+git() {
+ if [[ $# -gt 0 ]] && [[ "$1" == "status" ]]; then
+ shift
+ $(whence -p git) status -uno "$@"
+ else
+ $(whence -p git) "$@"
+ fi
+}
+fi
+
################# OS SPECIFIC #################
case $(uname) in
diff --git a/.zshrc-linux b/.zshrc-linux
index 904ee51..f78c226 100644
--- a/.zshrc-linux
+++ b/.zshrc-linux
@@ -7,30 +7,3 @@ alias ls='ls --color=auto'
alias ll='ls -lh --color=auto'
export PAGER='less -R'
-
-################## FUNCTIONS ##################
-
-# bits to human readable value
-b2h() {
- local suffixes=( 'B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y' )
- local sindex=1
- local val=$1
- [[ -z $(echo $1 | grep "^[0-9]*$") ]] && read val
-
- while [[ $(echo $val / 1024 | bc) -ne 0 ]]; do
- val=$(echo "scale=2; $val / 1024" | bc)
- let sindex=sindex+1
- done
-
- echo "${val}${suffixes[$sindex]}"
-}
-
-# ignore non-tracked files
-git() {
- if [[ $# -gt 0 ]] && [[ "$1" == "status" ]]; then
- shift
- $(which -p git) status -uno "$@"
- else
- $(which -p git) "$@"
- fi
-}
diff --git a/.zshrc-linux-desktop b/.zshrc-linux-desktop
index ec2a5fb..f1808ac 100644
--- a/.zshrc-linux-desktop
+++ b/.zshrc-linux-desktop
@@ -1,396 +1,9 @@
################### ALIASES ##################
alias ssh-socks='ssh -C2qTnN -D 9853 shmibbles.me'
-alias sx='startx'
if [[ "$(whence sshfs)" != "" ]] then
alias smounth='mkdir -p ~/shmibbles.me; sshfs shmibbles.me: ~/shmibbles.me'
alias smountw='mkdir -p ~/shmibbles.me; sshfs shmibbles.me:/usr/local/www/apache24/data/ ~/shmibbles.me'
alias sumount='fusermount -u ~/shmibbles.me; rmdir ~/shmibbles.me'
fi
-
-################## FUNCTIONS ##################
-
-# list stats about mpd library file types, to motivate me
-# to do better!
-mpd-filetypes() {
- local pattern
-
- # if args exist, read them as file extensions in a pattern
- if
- if [[ ! -z "$@" ]]; then
- pattern=$(echo "$@" | sed -e 's/\s/|/g' -e 's/\(.*\)/(\1)/')
- else
- # else hackily yoink recognised types from mpd --version
- pattern=$(mpd --version \
- | sed -n '1h; 1!H; ${g; s/.*Decoders plugins:\(.*\)Output.*/\1/g; p}' \
- | sed -e 's/.*\]//' | tr -d '\n' \
- | sed -e 's/^ //' -e 's/\s/|/g' -e 's/\(.*\)/(\1)/')
- fi
-
- # find file counts
- local i=1
- local total=0
- local totalstr='total'
- local counts=()
- local types=()
- find ~/music -type f -regextype posix-extended \
- -regex ".*\.$pattern" | grep -oE "\.$pattern$" \
- | sort | uniq -c | sed -e 's/^\s*\([0-9]* \)\./\1/' | \
- while read -A line; do
- counts[$i]=${line[1]}
- types[$i]=${line[2]}
- total=$(( $total + ${line[1]} ))
- i=$(( $i + 1 ))
- done
-
- # calculate percentages
- local twidth=0
- local cwidth=0
- local percentages=()
- for i in {1..${#types}}; do
- percentages[$i]="%$(calc -p \
- "a=${counts[$i]} * 100 / $total; round(a, 5-digits(a), 16)" \
- | tr -d '~')"
-
- done
-
- types=( 'type' "${types[@]}" 'total' )
- counts=( 'count' "${counts[@]}" $total )
- percentages=( 'percent' "${percentages[@]}" ' ')
-
- # calculate padding widths
- for i in {1..${#types}}; do
- if [[ ${#types[$i]} -gt $twidth ]]; then
- twidth=${#types[$i]}
- fi
-
- if [[ ${#counts[$i]} -gt $cwidth ]]; then
- cwidth=${#counts[$i]}
- fi
- done
-
-
- # print results
- local linelen=$(( $twidth + $cwidth + 13 ))
- local j
- echo -n "┌"
- for (( j=0; j < $linelen; j++ )); do
- echo -n "─"
- done
- echo "┐"
-
- for i in {1..${#types}}; do
- if [[ $i -eq 2 || $i -eq ${#types} ]]; then
- echo -n "├"
- for (( j=0; j < $linelen; j++ )); do
- echo -n "─"
- done
- echo "┤"
- fi
-
- if [[ $i -eq 1 ]]; then
- printf "│ %${twidth}s " "${types[$i]}"
- else
- printf "│ %${twidth}s: " "${types[$i]}"
- fi
-
- printf "%${cwidth}s" "${counts[$i]}"
-
- if [[ $i -eq 1 || $i -eq ${#types} ]]; then
- printf " %-7s │\n" "${percentages[$i]}"
- else
- printf ", %-7s │\n" "${percentages[$i]}"
- fi
- done
-
- echo -n "└"
- for (( j=0; j < $linelen; j++ )); do
- echo -n "─"
- done
- echo "┘"
-}
-
-# take a screenshot, upload to /img/scrot, and update current symlink
-ssh-scrot() {
- archey3
-
- local name
- if [[ "$1" != "" ]]; then
- name=$1
- else
- echo -n "name: "
- read name
- fi
-
- local date=$(date +'%Y-%m-%d')
-
- local folder="http/img/scrot"
- ssh shmibbles.me "mkdir -p $folder/$date"
-
- if [[ "${?#0}" != "" ]]; then
- return 1
- fi
-
- ssh shmibbles.me "cd $folder; rm current 2>/dev/null; ln -s $date current"
-
- for i in {3..1}; do
- echo -n "$i "
- sleep 1
- done
-
- echo 'cheese!'
- sleep .1
-
- scrot /tmp/$name.png
- convert -scale 250x /tmp/$name.png /tmp/${name}_small.png
-
- scp /tmp/$name.png /tmp/${name}_small.png shmibbles.me:http/img/scrot/$date
-
- echo "https://shmibbles.me/img/scrot/$date/$name.png" | tr -d '\n' | xclip -i -selection clipboard
- echo "https://shmibbles.me/img/scrot/$date/$name.png" | tr -d '\n' | xclip -i -selection primary
- echo "https://shmibbles.me/img/scrot/$date/${name}_small.png" | tr -d '\n' | xclip -i -selection clipboard
- echo "https://shmibbles.me/img/scrot/$date/${name}_small.png" | tr -d '\n' | xclip -i -selection primary
-
- echo 'sent!'
-
- rm /tmp/$name.png /tmp/${name}_small.png
-
-}
-
-make-gif-old() {
-
- if [[ -z "$1" ]]; then
- break
- fi
-
- rm -f make-gif-palette.png
- rm -f make-gif-palette.png
- rm -f make-gif-in
-
- rm -f make-gif-in
-
- ln -s "$1" make-gif-in
-
- local start
- echo -n "start [00:00:00]: "
- read start
- if [[ -z "$start" ]]; then
- start="00:00:00"
- fi
-
- local length
- echo -n "length [full]: "
- read length
- if [[ -z "$length" ]]; then
- t=""
- length=""
- else
- t="-t"
- fi
-
- local fps
- echo -n "fps [10]: "
- read fps
- if [[ -z "$fps" ]]; then
- fps="10"
- fi
-
- local width
- echo -n "width [480]: "
- read width
- if [[ -z "$width" ]]; then
- width="480"
- fi
-
- local subs
- echo -n "use subtitles? [y/N]: "
- read subs
- if [[ "$subs" == "y" || "$subs" == "Y" ]]; then
- subs="true"
- else
- subs=""
- fi
-
- if [[ $subs ]]; then
- ffmpeg -y -ss "$start" $t "$length" -i "$1" \
- -copyts -vf "subtitles=make-gif-in,fps=$fps,scale=$width:-1:flags=lanczos,palettegen" make-gif-palette.png
- ffmpeg -ss "$start" $t "$length" -i "$1" -i make-gif-palette.png \
- -copyts -filter_complex \
- "subtitles=make-gif-in,fps=$fps,scale=$width:-1:flags=lanczos[x];[x][1:v]paletteuse" \
- out.gif
- else
- ffmpeg -y -ss "$start" $t "$length" -i "$1" \
- -vf "fps=$fps,scale=$width:-1:flags=lanczos,palettegen" make-gif-palette.png
- ffmpeg -ss "$start" $t "$length" -i "$1" -i make-gif-palette.png -filter_complex \
- "fps=$fps,scale=$width:-1:flags=lanczos[x];[x][1:v]paletteuse" \
- out.gif
- fi
-
- rm -f make-gif-palette.png
- rm -f make-gif-in
-}
-
-# export a section of a video to gif
-make-gif() {
-
- local i
-
- local infile=""
- local outfile="out.gif"
- local start="00:00:00"
- local t=""
- local length=""
- local fps="10"
- typeset -i fps
- local width="480"
- typeset -i width
- local subs="n"
-
- # parse args
- local assign=false
- local assignopt=""
- local interact=true
- for i in "$@"; do
- if [[ $assign ]]; then
- assign=false
- case $assignopt in
- # output
- -o) outfile="$i" ;;
- # start
- -s) start="$i" ;;
- # length
- -l) t="-t"; length="$i" ;;
- # fps
- -f) fps="$i" ;;
- # width
- -w) width="$i" ;;
- # subs?
- -t) subs="y" ;;
- *)
- >&2 echo "err: unrecognised option"
- return
- ;;
- esac
- else
- case $i in
- -*)
- assign=true
- assignopt="$i"
- interact=false
- ;;
- *)
- if [[ -z "$infile" ]]; then
- infile="$i"
- else
- >&2 echo "err: multiple inputs specified"
- return
- fi
- ;;
- esac
- fi
- done
-
- if [[ $assign ]]; then
- >&2 echo "err: malformed arg"
- return
- fi
-
- if [[ -z "$infile" ]]; then
- >&2 echo "err: no input specified"
- return
- fi
-
- # interactive prompting
- if [[ $interact ]]; then
- read "i?start [00:00:00]: "
- if [[ "$i" ]]; then
- start="$i"
- fi
-
- read "i?length [full]: "
- if [[ "$i" ]]; then
- t="-t"
- length="$i"
- fi
-
- read "i?fps [10]: "
- if [[ "$i" ]]; then
- fps="$i"
- fi
-
- read "i?width [480]: "
- if [[ "$i" ]]; then
- width="$i"
- fi
-
- read -q "subs?use subtitles? [y/N]: "
- >&2 echo -e "\n"
-
- read "i?write to: "
- if [[ "$i" ]]; then
- outfile="$i"
- fi
- fi
-
- rm -f make-gif-palette.png
- rm -f make-gif-palette.png
- rm -f make-gif-in
-
- ln -s "$infile" make-gif-in
-
- >&2 echo "converting..."
-
- if [[ "$subs" == "y" ]]; then
- ffmpeg -loglevel 0 -y -ss "$start" $t "$length" -i "$infile" \
- -copyts -vf "subtitles=make-gif-in,fps=$fps,scale=$width:-1:flags=lanczos,palettegen" make-gif-palette.png
- ffmpeg -loglevel 0 -ss "$start" $t "$length" -i "$infile" -i make-gif-palette.png \
- -copyts -filter_complex \
- "subtitles=make-gif-in,fps=$fps,scale=$width:-1:flags=lanczos[x];[x][1:v]paletteuse" \
- make-gif-out
- else
- ffmpeg -loglevel 0 -y -ss "$start" $t "$length" -i "$infile" \
- -vf "fps=$fps,scale=$width:-1:flags=lanczos,palettegen" make-gif-palette.png
- ffmpeg -loglevel 0 -ss "$start" $t "$length" -i "$infile" -i make-gif-palette.png -filter_complex \
- "fps=$fps,scale=$width:-1:flags=lanczos[x];[x][1:v]paletteuse" \
- make-gif-out
- fi
-
- >&2 echo "optimising..."
-
- rm -f make-gif-palette.png
- rm -f make-gif-in
-
- gifsicle -O3 -o "$outfile" make-gif-out
-
- rm -f make-gif-out
-
- >&2 echo "done!"
-}
-
-# um...
-fuck() {
- local fuck="fuck"
- while true; do
- echo -en "\e[$((RANDOM%2));$((RANDOM%8+30))m"
-
- for i in {1..${#fuck}}; do
- if [[ $((RANDOM%2)) -eq 1 ]]; then
- echo -n $fuck[$i] | tr '[:lower:]' '[:upper:]'
- else
- echo -n $fuck[$i]
- fi
- done
-
- for i in {1..$((RANDOM%20))}; do
- echo -n " "
- done
- done
-}
-
-tmr() {
- transmission-daemon
- sleep 1
- transmission-remote-cli
- transmission-remote localhost --exit
-}