s(hortcut)-ack: a faster way to use ag, ack (or grep)!
The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:
s(hortcut)-ag/ack/grep: a faster way to use ag, ack, or grep!
sag / sack / sgrep act as wrappers for ag / ack / grep to provide convenience for the repetitive menial tasks when searching through codebases via the command line.
ag is a faster version of ack!*
*Out of the box, it includes some additional file that ack skips by default in its searches.
To learn more about ag, and how to install it:
ack is the replacement for grep!
Here is why you should use ack over grep: http://betterthangrep.com/
(Now that you are sold on ack) To install ack in a one-line script:
curl -L http://betterthangrep.com/ack-standalone > ~/bin/ack && chmod 0755 ~/bin/ack
Open a terminal and run the following:
git clone https://github.com/sampson-chen/sack.git && cd sack && chmod +x install_sack.sh && ./install_sack.sh
You can use sag / sack in exactly the same way you currently use ag / ack! Woot!
For why sack is faster (and more fun!) to use, read on about its main / side features...
sag / sack prefixes shortcut tags to ag / ack's search results:
[email protected]:~/src$ sack thumbnail
... (omitted results) /home/user/src/reviewboard/reviewboard/attachments/mimetypes.py  6:from djblets.util.templatetags.djblets_images import thumbnail  120: def get_thumbnail(self):  125: return mark_safe('')  135: def get_thumbnail(self):  136: """Returns a thumbnail of the image."""  137: return mark_safe(''  138: % (thumbnail(self.attachment.file, size='1000x1000'),  146: def get_thumbnail(self):  157: return mark_safe('%s'
Now, instead of having to spend time tediously navigating to some deep directory and typing out the file name, simply do:
[email protected]:~$ F 21
And sack will open the file associated with that particular search result with your favorite editor (currently supports both vim and emacs: see ~/.sackrc after installation) and even go to the right line for you automatically. (It doesn't have to be "F", see config file for reassigning the shortcut command)
The repetitive 10-15 sec chore has now been reduced to only 2 keystrokes (~1 second)!! More importantly, now you won't lose your train of throught from mentally context switching from the task at hand to deal with menial things like typing out a file path. Yay productivity!!
(For why removing such distractions is important to coding "in the zone", see the excellent Joel Test: http://www.joelonsoftware.com/articles/fog0000000043.html)
Note that whenever you perform a search in any terminal with sack, you can use the shortcuts in all other terminals (including new ones).
So now you can use one terminal to keep the search results open for reference, and use other terminals to open the files with shortcuts!
Profiles allow you to specify "preset" flags and directories, so you don't have to waste keystrokes typing them out each time, or having to change directories to include the folders you need to search.
[email protected]:~$ sack -sp RB
will switch you to the "RB" profile. Now any searches via sack will run with this profile's preset flags (e.g. flags="-ia -A 2 -B 3") and under this profile's preset directories (e.g. directories="~/src/reviewboard/ ~/src/rbtools ~/src/djblets")
Now suppose you are working under some deep directory in terminal:
and you wanted to search the all relevant codebases to find all locations where a particular function is invoked.
The old options were:
Now you can simply do:
[email protected]:~/src/...//.../diffs$ sack pattern1
And the rest is taken care of for you.
no_profileprofile is special: it never uses any preset flags or search directories. sack behaves exactly like ack while under
no_profile(except for the shortcuts)
To find out which profile you are currently on:
sack -wp sack --whichprofile
To switch to a different profile (
no_profileis the empty profile):
sack -sp PROFILE_NAME sack --switchprofile no_profile
To rename the current profile:
sack -rp NEW_PROFILE_NAME sack --renameprofile ReviewBoard
To set new preset flags to use for the current profile: (All searches run using this profile will use these flags)
sack -sf NEW_FLAGS sack --setflags -ia -A 2 -B 3
To set new preset directory(s) to use for the current profile: (All searches will be run under this directory with this profile)
sack -sd DIRECTORY_1 DIRECTORY_2 DIRECTORY_3 sack --setdirectory ~/src/reviewboard ~/src/rbtools ~/src/djblets
To add a new empty profile:
sack -anp PROFILE_NAME sack --addnewprofile ReviewBoard
To show the current available profiles:
sack -lp sack --listprofiles
Additional features / functionalities to be implemented:
install_sack.shto also install ack if it's not already on the system.