m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/ch
diff options
context:
space:
mode:
authorMarcin Chrzanowski <m@m-chrzan.xyz>2023-03-26 13:49:36 +0200
committerMarcin Chrzanowski <m@m-chrzan.xyz>2023-03-26 13:49:36 +0200
commit355d4996dc32988aabe000fbfaa1a9bbdd9ec585 (patch)
treef4af7671f8ed4fd9138d5fe5a723b64046de456f /ch
parent2a5b14312110abee3a70a2f59a8deacd6929031a (diff)
Add initial scripts
Diffstat (limited to 'ch')
-rwxr-xr-xch30
1 files changed, 30 insertions, 0 deletions
diff --git a/ch b/ch
new file mode 100755
index 0000000..e989716
--- /dev/null
+++ b/ch
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+# Helper script for my cheatsheets system.
+# USAGE: ch
+# This will open a fzf menu over the `~/cheatsheets` directory.
+# You can select one of the files there, or use the special command `new` which
+# creates a new file (you will be prompted for a title, which should not include
+# the .md extension).
+# NOTE: Currently hardcodes cheatsheets directory to `~/cheatsheets`.
+
+prefix=~/cheatsheets/
+suffix=.md
+sheets=("$prefix"*"$suffix")
+sheets=("${sheets[@]#"$prefix"}")
+sheets=("${sheets[@]%"$suffix"}")
+sheets=("${sheets[@]}" new)
+
+sheet=$(printf '%s\n' "${sheets[@]}" | fzf)
+
+if [[ "$sheet" == "new" ]]; then
+ echo -n "enter new cheatsheet name: "
+ read new_sheet
+ file="${prefix}${new_sheet}${suffix}"
+ $VISUAL $file
+ exit 0
+fi
+
+file="${prefix}${sheet}${suffix}"
+
+[[ -f $file ]] && $VISUAL $file