Skip to content

Instantly share code, notes, and snippets.

@yeiichi
Created December 26, 2024 04:45
Show Gist options
  • Save yeiichi/1cd955cd10f0aa85538399b1eb79d280 to your computer and use it in GitHub Desktop.
Save yeiichi/1cd955cd10f0aa85538399b1eb79d280 to your computer and use it in GitHub Desktop.
Opens ./meetings/yyyymmddHHMM/index.rst with Vim.
#!/usr/bin/env zsh
my_name=$(basename "$0")
display_help() {
echo usage: "${my_name}"
}
main() {
printf "*** Opens ./meetings/yyyymmddHHMM/index.rst with Vim. ***\n"
printf "\033[93mMeeting Date?(yyyymmdd) >> \033[0m"
read -r mtg_date
# Find candidate directories
dirs=$(find ./meetings -type d -maxdepth 1 -name "${mtg_date}*")
num_of_dirs=$(echo "${dirs}" | wc -l)
# Specify a single file path.
if [[ "${num_of_dirs}" -ne 1 ]]; then
{
printf "\033[93mStart Time?(HHMM) >> \033[0m"
read -r start_time
fpath="${mtg_date}${start_time}"/index.rst
}
else
fpath="${dirs}"/index.rst
fi
# Check the target_rst file.
[[ ! -f "${fpath}" ]] && echo 'No match found.' && exit
# Open the target file with vim.
echo "Opening ${fpath}..."
sleep 3
vim "${fpath}"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment