Skip to content

Instantly share code, notes, and snippets.

@tayabsoomro
Created August 20, 2025 18:32
Show Gist options
  • Select an option

  • Save tayabsoomro/ef6248a100de1bb3cf7b33476b3bfdce to your computer and use it in GitHub Desktop.

Select an option

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
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