From 69b83bb4e040c2e51550deacbcea0a30626caafc Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Fri, 20 Apr 2018 14:13:04 +0530 Subject: [PATCH] Autocreate folder and allow for spaces in base_path --- mark | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mark b/mark index a4d4458..6bb09be 100755 --- a/mark +++ b/mark @@ -1,20 +1,21 @@ #!/usr/bin/env bash source ~/.markrc +[[ -d "$base_path" ]] || mkdir -p "$base_path" today=$(date +%Y-%m-%d\ %H:%M:%S) -file_path=$base_path/$(date +%Y-%m).txt +file_path="$base_path/$(date +%Y-%m).txt" login_message="$username $today $login_message" logout_message="$username $today $logout_message" # Login if it is the first message of the day -if [[ -f $file_path ]]; then +if [[ -f "$file_path" ]]; then last_line=$(tail -n1 $file_path) last_day=$(echo $last_line | sed 's/[^ ]* [^-]*-[^-]*-\([^ ]*\).*/\1/') if [[ $last_day != $(date +%d) ]]; then - echo $login_message >> $file_path + echo $login_message >> "$file_path" fi else - echo $login_message >> $file_path + echo $login_message >> "$file_path" fi case "$*" in