Created
August 20, 2025 18:32
-
-
Save tayabsoomro/ef6248a100de1bb3cf7b33476b3bfdce to your computer and use it in GitHub Desktop.
A simple command logging function to be used to store history of commands that were run for a particular analysis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| note() { | |
| COMMANDS_FILE="$(pwd)/commands.sh" | |
| if [ $# -eq 0 ]; then | |
| echo "Error: No command provided to note" | |
| return 1 | |
| fi | |
| # Get the last command from history (which includes the 'note' prefix) | |
| local last_cmd=$(history 1 | sed 's/^[ ]*[0-9]*[ ]*//') | |
| # Remove the 'note ' prefix to get just the actual command | |
| local actual_cmd=$(echo "$last_cmd" | sed 's/^note //') | |
| # Log the original command as typed | |
| echo "[$(date +'%F_%T')]: $actual_cmd" >> "$COMMANDS_FILE" | |
| # Execute the command | |
| eval "$actual_cmd" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment