cmarks
is command line bookmarks. Use this Zsh script to quickly save useful or important commands to a centralized location.
Requirements:
To get started:
- Save the
cmarks
file locally - Add
source path/to/cmarks
to your.zshrc
To use sync:
- Through GitHub.com:
- Create a GitHub Gist (private or public)
- Note the hash ID (in the url)
- Add the Gist hash ID to the config file
- With
cmarks
:- Run
cmarks -z [private|public]
(this will automatically update the config)
- Run
To override the default config location (~/.config/cmarks.cfg
), add export CMARKS_CONFIG=/my/cmarks/config
before sourcing.
Options for the config file are as follows:
cmarks_file=
github_gist_id=
Usage: cmarks [OPTION]
-B Add command(s) from history to bookmarks [uses fzf]
-b <num1>[-<num2>] Add command(s) from history to bookmarks
-D Delete bookmarked command(s) [uses fzf]
-d <num1>[-<num2>] Delete bookmarked command(s)
-h Show help and usage
-l List all bookmarked commands
-P Print bookmarked command(s) to stdout [uses fzf]
-p <num1>[-<num2>] Print bookmarked command(s) to stdout
-R Get bookmarked command(s) and append to history [uses fzf]
-r <num1>[-<num2>] Get bookmarked command(s) and append to history
-s push|pull Sync bookmarks with GitHub Gist
-z public|private Create new GitHub Gist for syncing (default: private)
-
Find the history index number for a recent command:
% fc -l 2387 glow README.md 2388 podman machine start 2389 podman pull fedora 2390 podman run -it fedora bash 2391 podman machine stop
-
Add a command to cmarks:
% cmarks -a 2388 % cmarks -l 1 2022-15-01 13:20 podman machine start
You can also reference previous commands with negative numbers:
% cmarks -a -1 % cmarks -l 1 2022-15-01 13:30 podman machine stop
Or use a range to capture multiple commands:
% cmarks -a 2388-2390 % cmarks -l 1 2022-15-01 13:20 podman machine start 2 2022-15-01 13:25 podman pull fedora 3 2022-15-01 13:30 podman run -it fedora bash
-
Print a bookmarked command:
% cmarks -p 3 podman run -it fedora bash
-
Get a bookmarked command and append to history:
% fc -l 2476 ansible-lint playbooks/site.yml 2477 ansible-playbook playbooks/site.yml % cmarks -g 2
Press
↑
to quickly access the command. You can also see the command in your history:% fc -l 2476 ansible-lint playbooks/site.yml 2477 ansible-playbook playbooks/site.yml 2478 cmarks -g 2 2479 podman pull fedora
-
Delete a bookmarked command:
% cmarks -d 2 % cmarks -l 1 2022-15-01 13:20 podman machine start 2 2022-15-01 13:30 podman run -it fedora bash
- Bookmarked commands have separate index numbers than shell history
- Index numbers are re-assigned when bookmarks are removed
- Sync is rudimentary, use with caution