# This also looks like it could be customized more than fzf:
# https://github.com/lotabout/skim
+# * aliases
+
+alias n=continue
+
+# quicker function definition
+alias 8='f(){'
+alias 9='};'
+
+
# * functions
dunstify -u critical -h string:x-dunst-stack-tag:profanity "$*"
_psrun=(dunstctl close-all)
}
-n() {
- dunstify -u critical -h string:x-dunst-stack-tag:profanity n
- _psrun=(dunstctl close-all)
-}
catnew() {
local dir file _
mv "${f[@]}" "$dest"
}
-# f execute. speculating this will come in handy.
+# f execute.
fe() {
"$@" "${f[@]}"
}
+# f maybe.
+#
+# usage: fm COMMAND... [-] FILES...
+#
+# Create ${f[@]} by running COMMAND on each of FILES, if the command
+# succeeds, add it to ${f[@]};
+#
+# The first arg that is an existing file starts the FILES args, or an arg "-".
+fm() {
+ local file end_arg=false in_files=false
+ local -a files cmd
+ f=()
+ for a; do
+ if [[ $a == - ]]; then
+ end_arg=true
+ break
+ fi
+ done
+ for a; do
+ if ! $in_files; then
+ if $end_arg; then
+ if [[ $a == - ]]; then
+ in_files=true
+ shift
+ continue
+ fi
+ elif [[ -L $a || -e $a ]]; then
+ in_files=true
+ else
+ cmd+=("$a")
+ shift
+ fi
+ fi
+ if $in_files; then
+ if "${cmd[@]}" "$a"; then
+ f+=("$a")
+ fi
+ fi
+ done
+}
+# example shortening:
+# for f in *; do t -x $a && sk $a; done
+# becomes
+# fm t -x *; fe sk
+
+
+# execute on executables
+# usage: xe COMMAND... [-] FILES...
+#
+# Filter FILES to be executable files (remove directories).
+#
+# The first arg that is an existing file starts the FILES args, or an arg "-".
+xe() {
+ local file end_arg=false in_files=false
+ local -a files cmd
+ for a; do
+ if [[ $a == - ]]; then
+ end_arg=true
+ break
+ fi
+ done
+ for a; do
+ if ! $in_files; then
+ if $end_arg; then
+ if [[ $a == - ]]; then
+ in_files=true
+ shift
+ continue
+ fi
+ elif [[ -L $a || -e $a ]]; then
+ in_files=true
+ else
+ cmd+=("$a")
+ shift
+ fi
+ fi
+ if $in_files; then
+ if [[ -f $a && -x $a ]]; then
+ files+=("$a")
+ fi
+ fi
+ done
+ if (( ${#files[@]} == 0 )); then
+ echo $0: error: no files found >&2
+ return 1
+ fi
+ "${cmd[@]}" "${files[@]}"
+}
+
+# execute on directories
+# usage: xd COMMAND... [-] FILES...
+#
+# Filter FILES to just directories
+#
+# The first arg that is an existing file starts the FILES args, or an arg "-".
+xd() {
+ local file end_arg=false in_files=false
+ local -a files cmd
+
+ for a; do
+ if [[ $a == - ]]; then
+ end_arg=true
+ break
+ fi
+ done
+ for a; do
+ if ! $in_files; then
+ if $end_arg; then
+ if [[ $a == - ]]; then
+ in_files=true
+ shift
+ continue
+ fi
+ elif [[ -L $a || -e $a ]]; then
+ in_files=true
+ else
+ cmd+=("$a")
+ shift
+ fi
+ fi
+ if $in_files; then
+ if [[ -d $a ]]; then
+ files+=("$a")
+ fi
+ fi
+ done
+ if (( ${#files[@]} == 0 )); then
+ echo $0: error: no files found >&2
+ return 1
+ fi
+ "${cmd[@]}" "${files[@]}"
+}
+
# Save some for loop typing. Run COMMAND on each of FILES, striping any
# leading paths.
#
-# CD_DIRECTORY is assumed if FILES are in the current directory.
+# CD_DIRECTORY is assumed if FILES exist in the current directory.
#
# usage: [ CD_DIRECTORY ] COMMAND... FILES..
forf() {
done
}
+t() { test "$@"; }
+
+
# * stuff that makes sense to be at the end
done
}
+# timetrap. it has a single letter name which it does not deserve to take up.
+tt() {
+ local f cmd
+ # get highest version if we have more than one.
+ for f in ~/.local/share/gem/ruby/*/bin/t; do
+ cmd=$f
+ done
+ $cmd "$@"
+ }
+
## work log
#
# note: database location is specified in ~/.timetrap.yml, currently /p/.timetrap.db
for (( i=days_back; i>=0; i-- )); do
day=$( date +%F -d @$((EPOCHSECONDS - 86400*i )) )
date "+%a %b %d" -d @$((EPOCHSECONDS - 86400*i )) | tr '\n' ' '
- /a/opt/timetrap/bin/t d -ftotal -s $day -e $day all -m '^w|lunch$'
+ tt d -ftotal -s $day -e $day all -m '^w|lunch$'
done
}
-to() { we t out -a "$@"; }
-ti() { we t in -a "$@"; }
+to() { we tt out -a "$@"; }
+ti() { we tt in -a "$@"; }
_tl() {
local in_secs
to "$*"
- t s lunch
- t in -a "$*"
+ tt s lunch
+ tt in -a "$*"
in_secs="$(date -d "${*//[_.]/ }" +%s)"
- m t out -a "$(date +%F.%T -d @$(( in_secs + 60*45 )) )"
- t s w
+ m tt out -a "$(date +%F.%T -d @$(( in_secs + 60*45 )) )"
+ tt s w
}
tl() {
we _tl "$@"