Skip to content

Instantly share code, notes, and snippets.

@sushichan044
Created September 8, 2025 14:23
Show Gist options
  • Select an option

  • Save sushichan044/3b7abd0027cd77db92331a1115ffa905 to your computer and use it in GitHub Desktop.

Select an option

Save sushichan044/3b7abd0027cd77db92331a1115ffa905 to your computer and use it in GitHub Desktop.
my memo shortcut
#!/bin/sh
__ensure_memo_base_directory() {
local memo_dir="$(pwd)/.sushichan044/memo"
mkdir -p "$memo_dir"
echo "$memo_dir"
}
memo() {
local provided_name="$1"
# remove extension if provided, and replace all slashes with dashes
if [[ -n "$provided_name" ]]; then
provided_name="${provided_name//\//-}"
provided_name="${provided_name// /-}"
fi
# remove extension if provided, but keep the name part
# this is useful if the user provides a name with extension like "my-memo.txt"
if [[ "$provided_name" == *.* ]]; then
provided_name="${provided_name%.*}"
fi
local memo_slug="${provided_name:-$(TZ=UTC-9 date +'%H-%M-%S')}"
local memo_base_dir=$(__ensure_memo_base_directory)
local memo_dir=$(TZ=UTC-9 date +'%Y%m%d')
local memo_file_path="$memo_base_dir/$memo_dir/$memo_slug.md"
mkdir_for_file "$memo_file_path"
touch "$memo_file_path"
# message for human, print to stderr
echo "✅ Memo created at: $memo_file_path." 1>&2
# print the file path to stdout, useful for piping
echo "$memo_file_path"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment