Skip to content

Instantly share code, notes, and snippets.

@MarcelFox
Last active March 15, 2023 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarcelFox/0236adec544a00396fe3902c803c9c24 to your computer and use it in GitHub Desktop.
Save MarcelFox/0236adec544a00396fe3902c803c9c24 to your computer and use it in GitHub Desktop.
bash function for agenda
function agenda() {
DIR_PATH="$HOME/.agenda"
if [ ! -d $DIR_PATH ]; then
mkdir $DIR_PATH
fi
if [ -z "$1" ]
then
if [ ! -f "$DIR_PATH/agenda.txt" ];
then
printf "File $DIR_PATH does not exists, create it? (y/n): ";
read var_decision;
if [[ $var_decision == "y" ]] || [[ $var_decision == "Y" ]];
then
touch "$DIR_PATH/agenda.txt"
elif [[ $var_decision == "n" ]] || [[ $var_decision == "N" ]];
then
printf "Ok, nothing done!\n";
else
printf "\n${BOLD}Please inform only 'y' or 'n'. Closing...${NO_STL}\n\n";
fi;
else
less +G $DIR_PATH/agenda.txt
fi
elif [ -n "$1" ]
then
var="$1"
case "$var" in
"-e"|"--edit")
if [ -z "$2" ]
then
emacs $DIR_PATH/agenda.txt --eval "(with-current-buffer \"agenda.txt\" (insert-current-date))"
elif [ -n "$2" ]
then
emacs $DIR_PATH/$2 --eval "(with-current-buffer \"$2\" (insert-current-date))"
fi
;;
"-n"|"--new")
if [ -z "$2" ]
then
echo "Please inform a file name (example: file.txt)"
elif [ -n "$2" ]
then
emacs $DIR_PATH/$2 --eval "(with-current-buffer \"$2\" (insert-current-date))"
fi
;;
"-r"|"--read")
if [ -z "$2" ]
then
echo "Please inform a file name (example: file.txt)"
elif [ -n "$2" ]
then
less +G $DIR_PATH/$2
if [[ $? -eq 1 ]]
then
printf "\nFile '$2' was not found.\n\n"
fi
fi
;;
"-l"|"--list")
ls $HOME/.agenda/ | awk "/txt/ && !/~/ && !/#/"
;;
"-h"|"--help")
echo "AGENDA:"
echo
echo "usage: agenda [args] [file ..]"
echo
echo "Args:"
echo " -e | --edit [FILE] Edit/Create a file with emacs. If no file is provided, edits agenda.txt"
echo " -n | --new [FILE] Creates a new file for edition with emacs"
echo " -r | --read Opens a new file to be read with 'less'"
echo " -l | --list Lists the available text files under $DIR_PATH"
echo " -h | --help Show this menu"
;;
*)
echo "Unknown Argument. Try '--help'"
;;
esac
fi
}
@MarcelFox
Copy link
Author

MarcelFox commented Jan 31, 2018

Dependencies:

  • emacs-nox.
  • less.

Emacs configuration:

You must add the following configuration under your .emacs:
Emacs config

Installation:

  1. add the agenda function under your ~/.bashrc.
  2. you must export your function afterwards: export -f agenda
  3. run: $ source ~/.bashrc

Usage:

$ agenda --help
AGENDA:

usage: agenda [args] [file ..]

Args:
  -e|--edit [FILE]      Edit/Create a file with emacs. If no file is provided, edits agenda.txt
  -n|--new  [FILE]      Creates a new file for edition with emacs
  -r|--read             Opens a new file to be read with 'less'
  -l|--list             Lists the available text files under /home/mfox/.agenda
  -h|--help             Show this menu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment