Take Command of your Cheatsheets with this script
Category: Shell Scripting
Date: 9 months ago
Views: 1.21K
Introduction:
In the world of shell scripting, simplicity and functionality often go hand in hand. The provided shell script is a testament to this philosophy. It serves as a versatile tool for both note-taking and managing cheatsheets, all within the familiar environment of the command line.
The Script:
#!/bin/zsh
if [[ $1 == "-e" ]] ; then
vim "${HOME}/.cheat/$2"
exit
fi
if [[ $1 == "-l" ]] ; then
ls "${HOME}/.cheat/"
exit
fi
less -p '^#.*' -R "${HOME}/.cheat/$1"
Usage:
The script offers three main functionalities:
Editing Notes/Cheatsheets: By providing the option
-e
followed by the name of the cheatsheet, the script opens the file in Vim for editing. For instance:./script.sh -e ffmpeg
This command opens theffmpeg
file for editing within the Vim text editor.Listing Available Cheatsheets: The option
-l
lists all available cheatsheets stored in the.cheat
directory. For example:./script.sh -l
This command displays a list of all cheatsheets present in the.cheat
folder.Viewing Cheatsheets: If neither
-e
nor-l
options are provided, the script assumes the argument is the name of the cheatsheet to view. It then displays the contents of the cheatsheet using theless
pager, highlighting lines starting with#
, which often denote comments or headings.
You can press v
while in less
command to enter editing mode with vim
Usage Optimization:
To streamline usage even further, creating an alias for this script is a clever move. For instance, you could set up an alias like `cheat
` that points to the script's location. This way, invoking the script becomes as simple as typing `cheat
` followed by the desired command or option.
Moreover, leveraging the autocomplete feature of zsh can enhance efficiency even more. By configuring Zsh's autocomplete settings, you can enable suggestions for cheatsheet names stored within the `.cheat
` directory. For instance, when typing `cheat
` and pressing the `TAB` key, Zsh can present a dropdown menu of all available cheatsheets, allowing for quick selection without the need to recall filenames manually. This integration seamlessly integrates the script into your workflow, making accessing cheatsheets a breeze.
In practice, this autocomplete feature looks like this:
Benefits:
Efficiency: With this script, accessing and managing cheatsheets becomes a seamless process directly from the command line, saving valuable time and effort.
Organization: All cheatsheets are stored within the
.cheat
directory, keeping your notes neatly organized and easily accessible.Customization: The script is easily customizable to suit individual preferences or workflow requirements. Users can modify it to integrate additional features or tailor it to specific use cases.
Conclusion:
In the realm of command-line productivity, having quick access to notes and cheatsheets can greatly enhance workflow efficiency. This shell script provides a simple yet effective solution, empowering users to manage their notes effortlessly and focus on the task at hand. With its versatility and ease of use, it stands as a valuable tool in the toolkit of any command-line aficionado.
0 Comments, latest
No comments.