aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jonas Gunz <himself@jonasgunz.de> 2021-05-30 12:38:06 +0200
committerGravatar Jonas Gunz <himself@jonasgunz.de> 2021-05-30 12:38:06 +0200
commitaff5e973c018f57172a3218e6a7579f667f2222c (patch)
tree27033375dbf7f3e229500cc4d01746573c0f0a81
parent08737a0ccf016dbc17b0ca67aeeb9004de6a340b (diff)
downloaddotfiles-aff5e973c018f57172a3218e6a7579f667f2222c.tar.gz
add board.bash
-rw-r--r--bash/board.bash62
1 files changed, 62 insertions, 0 deletions
diff --git a/bash/board.bash b/bash/board.bash
new file mode 100644
index 0000000..08f4da1
--- /dev/null
+++ b/bash/board.bash
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+BB_HIST_DIR="$HOME/.cache/bashboard/"
+BB_SHORTCUT=()
+
+[ ! -d "$BB_HIST_DIR" ] && mkdir -p "$BB_HIST_DIR"
+
+# format
+# NUM YYYY-MM-DD PATH
+
+function cd {
+ local BB_PWD
+ local BB_GREP_RET
+ local BB_NUM BB_DATE BB_DIR
+
+ builtin cd "$@" || return $?
+ [ -f "$BB_DIR/history" ] || touch "$BB_HIST_DIR/history"
+ BB_PWD="$(pwd)"
+
+ [ "$BB_PWD" = "$HOME" ] && return
+
+ BB_GREP_RET=$(grep -P "^\d+ \d+ \Q$BB_PWD\E$" "$BB_HIST_DIR/history")
+ read -r BB_NUM BB_DATE BB_DIR <<< "$BB_GREP_RET"
+ if [ -n "$BB_NUM" ]; then
+ BB_NUM=$((BB_NUM+1))
+ perl -p -i -e "s|^\d+ \d+ \Q$BB_PWD\E$|$BB_NUM $(date +%s) $BB_PWD|g" \
+ "$BB_HIST_DIR/history"
+ else
+ echo "1 $(date +%s) $BB_PWD" >> "$BB_HIST_DIR/history"
+ fi
+}
+
+function bashboard {
+ local BB_NUM BB_DATE BB_DIR
+ local line
+ local cnt
+
+ BB_SHORTCUT=()
+
+ cnt=0
+ while read -r line; do
+ read -r BB_NUM BB_DATE BB_DIR <<< "$line"
+ echo "[$cnt] ${BB_DIR##$HOME/}"
+
+ BB_SHORTCUT+=("$BB_DIR")
+
+ cnt=$((cnt+1))
+ done <<< "$(sort -nr "$BB_HIST_DIR/history" | head -n 5)"
+
+ # TODO recently used
+}
+
+function bb {
+ if [ $# -eq 0 ]; then
+ bashboard
+ return
+ fi
+
+ cd "${BB_SHORTCUT[$1]}" || return
+}
+
+bashboard