This script, bookmark.sh, allows you to save your most recent shell commands to a file, with the option to add a comment for context. It's designed to help you keep track of the commands you've run for specific tasks or projects, directly from your shell.
- Bash shell
- Access to the
historycommand - Permission to create and write to files in your home directory
To ensure this script can access and manipulate the current shell's history, it must be run using the source command. You can simplify this process by setting up an alias:
-
Open your shell's configuration file (
~/.bashrc,~/.bash_profile,~/.zshrc, etc.) in your preferred text editor. -
Add the following alias command to the file:
alias bookmark='source $(pwd)/bookmark.sh'- Apply the changes by reloading your shell configuration:
source ~/.bashrc # Or use the appropriate configuration file for your shellUsage
After setting up the alias, you can start using bookmark to save your command history. Here are some examples of how to use it:
bookmark -c "This is a cool comment"
bookmark 5
bookmark -c "These are my last 5 commands" 5