Created
August 13, 2024 16:12
-
-
Save sixlive/4c31d9a4a1fe318c2478dbe343474927 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
script_name="$(basename "$0")" | |
_verify_dependencies() { | |
_print_err() { | |
printf "[$SCRIPT_NAME] \033[31m%s\033[0m\n" "$1" | |
} | |
if ! command -v gum &>/dev/null; then | |
_print_err "charmbracelet/gum must be installed!" | |
_print_err "See: https://github.com/charmbracelet/gum" | |
exit 1 | |
fi | |
} | |
main() { | |
_verify_dependencies | |
local action="${1:-""}" | |
local scratchDir="$HOME/scratches" | |
if [ ! -d "$scratchDir" ]; then | |
mkdir -p $scratchDir | |
fi | |
cd $scratchDir | |
# Check if 'open' argument is passed | |
if [ "$action" == 'open' ]; then | |
ls $scratchDir | | |
gum filter --limit 1 --header "Pick a scratch to open" --reverse | | |
xargs nvim | |
else | |
# Create a timestamp with the format YYYY-MM-DD-HHMM-TZ | |
local timestamp="$(date +"%Y-%m-%d-%H%M%z")" | |
local fileName | |
fileName="$(gum input --placeholder=$timestamp)" | |
if [ -z "$fileName" ]; then | |
fileName=$timestamp | |
else | |
fileName="$timestamp-$fileName" | |
fi | |
local filePath="$scratchDir/$fileName.md" | |
# Open neovim with the specified file path and format as Markdown | |
nvim -c "set ft=markdown" "$filePath" | |
fi | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment