cleanup of the output of the program. Updated README.
[bash-notes.git] / SOURCE / CORE / helpers.sh
CommitLineData
fb711183 1# check if input is a number, returns false or the number itself
b1e2a018 2check_noteID() {
fb711183 3 IN=$1
4 case $IN in
5 ''|*[!0-9]*)
3bd93e7f 6 false
fb711183 7 ;;
8 *)
9 echo "$IN"
10 ;;
11 esac
12}
13
b1e2a018 14helptext() {
fb711183 15 echo "Usage:"
efa3e607 16 echo " $0 [PARAMS] [note ID]..."
fb711183 17 echo ""
18 echo "${BASENAME} parameters are:"
9eb02251 19 echo -e " -h | --help\t\t\t: This help text"
20 echo -e " -p | --plain\t\t\t: Output is in plain text"
21 echo -e "\t\t\t\t (without this option the output is formatted)"
22 echo -e "\t\t\t\t (this option must precede all others)"
23 echo -e " -l | --list\t\t\t: List existing notes"
3951cc3d 24 echo -e " -a | --add=[\"<title>\"]\t: Add new note"
25 echo -e " -e | --edit=[<note>]\t\t: Edit note"
26 echo -e " -d | --delete=[<note> | all] : Delete single note or all notes at once"
27 echo -e " -s | --show=[<note>]\t\t: Display note using your favourite PAGER"
28 echo -e " -r | --restore=[<dir>]\t: Restore a previous backup from dir"
9eb02251 29 echo -e " -v | --version\t\t: Print version"
30 echo -e " --userconf\t\t\t: Export User config file"
31 echo -e " --backup [<dest>]\t\t: Backup your data in your destination folder"
3bd93e7f 32 echo -e " --showconf\t\t\t: Display running options"
33 echo -e " --sync\t\t\t: Sync notes to git repository"
fb711183 34 echo ""
efa3e607 35 echo -e "if a non option is passed and is a valid note ID, the note will be displayed."
fb711183 36}
9eb02251 37
b1e2a018 38configtext() {
1f4d7742 39 [ $USEGIT ] && GITUSE="enabled" || GITUSE="disabled"
3bd93e7f 40 if [ -n $GITCLIENT ]; then
41 CLIENTGIT="$( hostname )"
42 else
43 CLIENTGIT="$GITCLIENT"
44 fi
1f4d7742 45 clear
46 echo -e "${BASENAME} configuration is:"
3951cc3d 47
3bd93e7f 48 echo -e "\tbase directory: ${BASEDIR}/"
49 echo -e "\tnotes archive: ${NOTESDIR}/"
50 echo -e "\tnotes database: ${DB}"
51 echo -e "\trc file: $RCFILE"
52 echo -e "\tdebug file: /tmp/debug_bash-note.log"
53 echo
54 echo -e "\ttext editor: ${EDITOR}"
55 echo -e "\tterminal: ${TERMINAL}"
56 echo -e "\tjq executable: ${JQ}"
57 echo -e "\tPAGER: ${PAGER}"
58 echo
59 echo -e "\tGIT: ${GITUSE} - ${GIT}"
60 echo -e "\tGIT remote: ${GITREMOTE}"
61 echo -e "\tGIT sync delay: ${GITSYNCDELAY}"
62 echo -e "\tGIT client name: ${CLIENTGIT}"
3951cc3d 63}
64
6a193095 65# this function returns a random 2 words title
b1e2a018 66random_title() {
6a193095 67 # Constants
68 X=0
69 DICT=/usr/share/dict/words
70 OUTPUT=""
71
72 # total number of non-random words available
73 COUNT=$(cat $DICT | wc -l)
74
75 # while loop to generate random words
76 while [ "$X" -lt 2 ]
77 do
78 RAND=$(od -N3 -An -i /dev/urandom | awk -v f=0 -v r="$COUNT" '{printf "%i\n", f + r * $1 / 16777216}')
79 OUTPUT+="$(sed `echo $RAND`"q;d" $DICT)"
80 (("X = X + 1"))
81 [[ $X -eq 1 ]] && OUTPUT+=" "
82 done
83
84 echo $OUTPUT
85}
86