the_earnest/dotfiles
added godir and ffcut scripts
Commit 00e8e45a8914 · The Earnest · 2026-11-18 17:04 +0000
Comments
No comments yet.
Diff
diff --git a/bashrc b/bashrc
--- a/bashrc
+++ b/bashrc
@@ -164,8 +164,8 @@
rm "$TMPFILE"
}
-source ~/hg/godir/godir.bash
-source ~/hg/scripts/ffcut.bash
+source ~/.dotfiles/godir/godir.bash
+source ~/.dotfiles/scripts/ffcut.bash
INIT_DIR=storage/downloads
[[ -d "$INIT_DIR" ]] && cd "$INIT_DIR"
diff --git a/godir/TODO.txt b/godir/TODO.txt
new file mode 100644
--- /dev/null
+++ b/godir/TODO.txt
@@ -0,0 +1,6 @@
+things to fix about GoDir
+
+gd shared/Documents //doesn't wor
+
+should have multi-level search
+
diff --git a/godir/godir.bash b/godir/godir.bash
new file mode 100644
--- /dev/null
+++ b/godir/godir.bash
@@ -0,0 +1,134 @@
+function f {
+ FINDCMD="find"
+ for i in "$@"; do
+ FINDCMD+=" -iname '"
+ FINDCMD+='*'"$i"'*'
+ FINDCMD+=\'
+ done
+ echo FINDCMD=$FINDCMD
+ eval "$FINDCMD"
+}
+
+function g() {
+
+ if [[ "$1" == "-v" ]]; then
+ local VERBOSE=verbose
+ shift
+ fi
+
+ # case 1: invoked without args, go to home dir
+ if [[ $# -eq 0 ]]; then
+ [[ -n $VERBOSE ]] && echo gd: no argument, going to home dir
+ cd
+ return
+ fi
+
+ # treat all remaining args as a single string
+ ARG="$*"
+ TMPFILE="$TMPDIR"/find.tmp
+
+ # case 2: arg ends with fwd slash; possibly user invoked word
+ # completion; if it matches a direct subdir, use that, otherwise
+ # error
+ if [[ "${ARG: -1}" == '/' ]]
+ then
+ if [[ -d "$ARG" ]]; then
+ [[ -n $VERBOSE ]] && echo gd: \"$ARG\" is name of direct subdir - OK
+ cd "$ARG"
+ return
+ else
+ echo gd: error: direct subdir \"$ARG\" does not exist
+ [[ -n $VERBOSE ]] && echo gd: remove the slash if you want to go to a directory with a name containing \"${ARG%%/}\"
+ return
+ fi
+ fi
+
+ CONFIG_FILE=~/gd.conf
+ [[ -e "$CONFIG_FILE" ]] && source "$CONFIG_FILE"
+ [[ -z $MAXDEPTH ]] && MAXDEPTH=2
+
+ GD_PRUNE_FILE=~/gd.prune
+ if [[ -e "$GD_PRUNE_FILE" ]]
+ then
+ cat "$GD_PRUNE_FILE" | while read LINE; do
+ echo $LINE
+ done
+ fi
+
+ # case 4: must perform search
+ REM="$ARG" # remainder
+ while [[ -n "$REM" ]]
+ do
+ ARG="${REM%%/*}"
+ if [[ "$ARG" != "$REM" ]]
+ then
+ REM="${REM#*/}"
+ else
+ REM=""
+ fi
+
+ [[ -n $VERBOSE ]] && echo gd: searching subtree for \"$ARG\"
+ [[ -n $VERBOSE ]] && echo gd: MAXDEPTH=$MAXDEPTH
+
+ #find -maxdepth $MAXDEPTH -path './Android' -prune -o -type d -iname '*'"${ARG}"'*' -print >"$TMPFILE"
+ [[ -n $VERBOSE ]] && echo gd: PRUNE_EXPR=$PRUNE_EXPR
+ NAME_OPT="-iname"
+ #find -maxdepth $MAXDEPTH $PRUNE_EXPR -type d $NAME_OPT '*'"${ARG}"'*' -print | sed -e 's/^\.\///' >"$TMPFILE"
+ find -L -maxdepth $MAXDEPTH $PRUNE_EXPR -type d $NAME_OPT '*'"${ARG}"'*' '!' -exec test -e "{}/.nogd" ';' -print | sed -e 's/^\.\///' >"$TMPFILE"
+
+ N=$(cat "$TMPFILE"|wc -l)
+ if [[ $N -eq 0 ]]
+ then
+ echo gd: \"$ARG\" not found
+ rm "$TMPFILE"
+ return
+ fi
+
+ if [[ $N -eq 1 ]]
+ then
+ TARGET_DIR=$(cat "$TMPFILE")
+ [[ -n $VERBOSE ]] && echo gd: unique result: \"$TARGET_DIR\" - OK
+ cd "$TARGET_DIR"
+ rm "$TMPFILE"
+ continue
+ fi
+
+ if [[ $N -gt 1 ]]
+ then
+ [[ -n $VERBOSE ]] && echo gd: $N directories found for \"$ARG\"
+ cat -n "$TMPFILE"
+
+ local PROMPT="choose 1-$N: "
+ local NKEYSOPT="-n${#N}"
+ local KEY
+ read -n${#N} -p "$PROMPT" KEY
+ # echo newline if necessary
+ [[ ${#KEY} -eq ${#N} ]] && echo
+
+ if [[ -z "$KEY" ]]; then
+ [[ -n $VERBOSE ]] && echo "gd: no choice"
+ rm $TMPFILE
+ return
+ fi
+
+ if [[ ! "$KEY" =~ ^[0-9]+$ ]]
+ then
+ echo "gd: not a valid choice"
+ rm $TMPFILE
+ return
+ fi
+
+ # input is a number
+ if [[ $KEY -lt 1 || $KEY -gt $N ]]; then
+ echo "gd: not a valid choice"
+ return
+ fi
+
+ # get the chosen line from the tempfile
+ local TARGET_DIR=$(sed -n -e "$KEY p" "$TMPFILE")
+ cd "$TARGET_DIR"
+ rm $TMPFILE
+ fi
+
+ done
+}
diff --git a/godir/godir.bash.recursive b/godir/godir.bash.recursive
new file mode 100644
--- /dev/null
+++ b/godir/godir.bash.recursive
@@ -0,0 +1,122 @@
+function f {
+ FINDCMD="find"
+ for i in "$@"; do
+ FINDCMD+=" -iname '"
+ FINDCMD+='*'"$i"'*'
+ FINDCMD+=\'
+ done
+ echo FINDCMD=$FINDCMD
+ eval "$FINDCMD"
+}
+
+function _g()
+{
+ local ARG="$*"
+
+ # case 4: must perform search
+ CONFIG_FILE=~/gd.conf
+ [[ -e "$CONFIG_FILE" ]] && source "$CONFIG_FILE"
+ [[ -z $MAXDEPTH ]] && MAXDEPTH=2
+
+ [[ -n $VERBOSE ]] && echo gd: searching subtree for \"$ARG\"
+ [[ -n $VERBOSE ]] && echo gd: MAXDEPTH=$MAXDEPTH
+
+ GD_PRUNE_FILE=~/gd.prune
+ if [[ -e "$GD_PRUNE_FILE" ]]
+ then
+ cat "$GD_PRUNE_FILE" | while read LINE; do
+ echo $LINE
+ done
+ fi
+
+ TMPFILE="$TMPDIR"/find.tmp
+ #find -maxdepth $MAXDEPTH -path './Android' -prune -o -type d -iname '*'"${ARG}"'*' -print >"$TMPFILE"
+ [[ -n $VERBOSE ]] && echo gd: PRUNE_EXPR=$PRUNE_EXPR
+ find -maxdepth $MAXDEPTH $PRUNE_EXPR -type d -iname '*'"${ARG}"'*' -print | sed -e 's/^\.\///' >"$TMPFILE"
+ N=$(cat "$TMPFILE"|wc -l)
+ if [[ $N -eq 0 ]]
+ then
+ echo gd: \"$ARG\" not found
+ rm "$TMPFILE"
+ return
+ fi
+
+ if [[ $N -gt 1 ]]
+ then
+ [[ -n $VERBOSE ]] && echo gd: $N directories found for \"$ARG\"
+ cat -n "$TMPFILE"
+
+ local PROMPT="choose 1-$N: "
+ local NKEYSOPT="-n${#N}"
+ local KEY
+ read -n${#N} -p "$PROMPT" KEY
+ # echo newline if necessary
+ [[ ${#KEY} -eq ${#N} ]] && echo
+
+ if [[ -z "$KEY" ]]; then
+ [[ -n $VERBOSE ]] && echo "gd: no choice"
+ rm $TMPFILE
+ return
+ fi
+
+ if [[ ! "$KEY" =~ ^[0-9]+$ ]]
+ then
+ echo "gd: not a valid choice"
+ rm $TMPFILE
+ return
+ fi
+
+ # input is a number
+ if [[ $KEY -lt 1 || $KEY -gt $N ]]; then
+ echo "gd: not a valid choice"
+ fi
+
+ # get the chosen line from the tempfile
+ local TARGET_DIR=$(sed -n -e "$KEY p" "$TMPFILE")
+ cd "$TARGET_DIR"
+ rm $TMPFILE
+ return
+ fi
+
+ # if we get here, $N must be
+ # 1
+ TARGET_DIR=$(cat "$TMPFILE")
+ [[ -n $VERBOSE ]] && echo gd: unique result: \"$TARGET_DIR\" - OK
+ cd "$TARGET_DIR"
+ rm "$TMPFILE"
+}
+
+function g() {
+
+ if [[ "$1" == "-v" ]]; then
+ local VERBOSE=verbose
+ shift
+ fi
+
+ # case 1: invoked without args, go to home dir
+ if [[ $# -eq 0 ]]; then
+ [[ -n $VERBOSE ]] && echo gd: no argument, going to home dir
+ cd
+ return
+ fi
+
+ # treat all remaining args as a single string
+ local ARG="$*"
+
+ # case 2: arg ends with fwd slash; possibly user invoked word
+ # completion; if it matches a direct subdir, use that, otherwise
+ # error
+ if [[ "${ARG: -1}" == '/' ]]; then
+ if [[ -d "$ARG" ]]; then
+ [[ -n $VERBOSE ]] && echo gd: \"$ARG\" is name of direct subdir - OK
+ cd "$ARG"
+ return
+ else
+ echo gd: error: direct subdir \"$ARG\" does not exist
+ [[ -n $VERBOSE ]] && echo gd: remove the slash if you want to go to a directory with a name containing \"${ARG%%/}\"
+ return
+ fi
+ fi
+
+ _g "$ARG"
+}
diff --git a/godir/prunelogic b/godir/prunelogic
new file mode 100644
--- /dev/null
+++ b/godir/prunelogic
@@ -0,0 +1,8 @@
+ GD_PRUNE_FILE=~/gd.prune
+ if [[ -e "$GD_PRUNE_FILE" ]]
+ then
+ cat "$GD_PRUNE_FILE" | while read LINE; do
+ echo $LINE
+ done
+ fi
+
diff --git a/godir/test b/godir/test
new file mode 100755
--- /dev/null
+++ b/godir/test
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+#SS="abc/def/ghi/kkk"
+SS="$1"
+echo length= ${#SS}
+
+function zz() {
+ local FIRSTPART="${1%%/*}"
+ local REMAINDER
+ if [[ "$FIRSTPART" != "$1" ]]
+ then
+ REMAINDER="${1#*/}"
+ fi
+ echo handling $FIRSTPART
+ [[ -n "$REMAINDER" ]] && zz "$REMAINDER"
+}
+
+echo recursive
+zz "$SS"
+
+echo
+echo nonrecursive
+while [[ -n "$SS" ]]
+do
+ PP="${SS%%/*}"
+ if [[ "$PP" != "$SS" ]]
+ then
+ SS="${SS#*/}"
+ else
+ SS=""
+ fi
+ echo handling $PP
+done
+
diff --git a/scripts/ffcut.bash b/scripts/ffcut.bash
new file mode 100644
--- /dev/null
+++ b/scripts/ffcut.bash
@@ -0,0 +1,24 @@
+function ffcut() {
+ local error
+ if [[ $# -ne 3 ]]; then
+ error="error: expected 3 arguments, found $#\nusage: ffcut input-file start-time end-time"
+ elif [[ ! -e "$1" ]]; then
+ error="error: input file does not exist"
+ fi
+ if [[ -n "$error" ]]; then
+ echo -e "$error"
+ return 99
+ fi
+ name_no_ext=${1%.*}
+ ext=${1##*.}
+ ts_start=$(echo $2|tr ':.,' '___')
+ ts_stop=$(echo $3|tr ':.,' '___')
+ # or without tr, sth like:
+ # ts_start=${2//:/_}
+ # ts_stop=${3//:/_}
+ outfile="$name_no_ext snip $ts_start to $ts_stop.$ext"
+ echo output file: \"$outfile\"
+ ffmpeg -hide_banner -loglevel error -ss $2 -to $3 -i "$1" -map 0 -c copy "$outfile"
+ [[ $? -eq 0 ]] && echo OK
+ return $?
+}