diff options
author | Oskar <[email protected]> | 2024-07-24 13:58:17 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-07-24 13:58:17 +0200 |
commit | bc90aad16e0f2918c7c551152de0bf876ab52a3c (patch) | |
tree | 45f13fe5095d9e96d8754f5c37e01ef8423c9c84 | |
parent | ae1ec455c6f611de2149048b0772bbb56ca90172 (diff) |
script for replacing timestamp in logs for easy testing of -c
-rwxr-xr-x | test/test_replace_timestamp.sh | 24 | ||||
-rw-r--r-- | trashsys.c | 26 |
2 files changed, 37 insertions, 13 deletions
diff --git a/test/test_replace_timestamp.sh b/test/test_replace_timestamp.sh new file mode 100755 index 0000000..ffad66e --- /dev/null +++ b/test/test_replace_timestamp.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +LOG_DIR="/home/oskar/.trashsys/log" + +if [ -z "$1" ]; then + echo "Usage: $0 <replacement_string>" + exit 1 +fi + +REPLACEMENT="$1" + +if [ ! -d "$LOG_DIR" ]; then + echo "Directory $LOG_DIR does not exist." + exit 1 +fi + +for file in "$LOG_DIR"/*; do + if [ -f "$file" ]; then + echo "replacing trashed time in: $file" + awk -v replacement="$REPLACEMENT" 'NR % 5 == 0 {print replacement} NR % 5 != 0 {print $0}' "$file" > "$file.tmp" && mv "$file.tmp" "$file" + fi +done + +echo "Done." @@ -20,19 +20,19 @@ #define LONG_USAGE "tsr [options] filename(s)\n"\ "\n"\ "OPTIONS:\n"\ - " -t /tmp mode. tsr will use /tmp instead of the user's $HOME.\n"\ - " -y Answer 'yes' when pressing return on all [Y / N] prompts.\n"\ - " -n Answer 'no' when pressing return on all [Y / N] prompts.\n"\ - " -f Force answer 'yes' on all [Y / N] prompts. Prompt will not show.\n"\ - " -a Always ask with a [Y / N] prompt.\n"\ - " -l List all trashed files.\n"\ - " -L List all trashed files with more details.\n"\ - " -c Clear all trashed files that are older than the configured time limit.\n"\ - " -C Clear all trashed files regardless of age. Will prompt with a [Y / N] prompt.\n"\ - " -h Display this help message.\n"\ - " -R id Restore a file by ID. Use -l or -L to find the ID associated with the file.\n"\ - " -v Verbose mode, not recommended unless you are a developer.\n"\ - " -i Check for inconsistencies in the logs and trashed files (maybe implement)\n"\ + " -t /tmp mode. tsr will use /tmp instead of the user's $HOME.\n"\ + " -y Answer 'yes' when pressing return on all [Y / N] prompts.\n"\ + " -n Answer 'no' when pressing return on all [Y / N] prompts.\n"\ + " -f Force answer 'yes' on all [Y / N] prompts. Prompt will not show.\n"\ + " -a Always ask with a [Y / N] prompt.\n"\ + " -l List all trashed files.\n"\ + " -L List all trashed files with more details.\n"\ + " -c Clear all trashed files that are older than the configured time limit.\n"\ + " -C Clear all trashed files regardless of age. Will prompt with a [Y / N] prompt.\n"\ + " -h Display this help message.\n"\ + " -R id path(optional) Restore a file by ID. Use -l or -L to find the ID associated with the file.\n"\ + " -v Verbose mode, not recommended unless you are a developer.\n"\ + " -i Check for inconsistencies in the logs and trashed files (maybe implement)\n"\ "\n" #define MODE_NORMAL -1 #define MODE_YES 0 |