<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.9.1: http://docutils.sourceforge.net/" />
<title>The reStructuredText Cheat Sheet: Syntax Reminders</title>
<meta name="author" content="David Goodger <goodger@python.org>" />
<meta name="date" content="2012-06-22" />
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7434 2012-05-11 21:06:27Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borde
<h1>sack</h1>
<p>s(hortcut)-ack: a faster way to use ack (and grep)!</p>
<p>sack acts as a wrapper for ack to provide convenience for the repetitive menial tasks</p>
<h2>What is ack?</h2>
<p>ack is the replacement for grep!</p>
<p>Here is why you should use ack over grep: http://betterthangrep.com/</p>
<p>(Now that you are sold on ack) To install ack in a one-line script:</p>
<pre><code>curl http://betterthangrep.com/ack-standalone > ~/bin/ack && chmod 0755 !#:3
</code></pre>
<h2>How to Install:</h2>
<p>Open a terminal and run the following:</p>
<pre><code>git clone git@github.com:sampson-chen/sack.git && cd sack && chmod +x install_sack.sh && ./install_sack.sh
</code></pre>
<h2>How to Use:</h2>
<p>You can use sack in exactly the same way you currently use ack! Woot!</p>
<p>For why sack is faster (and more fun!) to use, read on about its main / side features...</p>
<h2>Main Feature 1 - Shortcuts:</h2>
<p>sack prefixes shortcut tags to ack's search res
raw .md file used in screenshot | |
---|---|
1 | sack |
2 | |
3 | s(hortcut)-ack: a faster way to use ack (and grep)! |
4 | |
5 | sack acts as a wrapper for ack to provide convenience for the repetitive menial tasks |
6 | |
7 | What is ack? |
8 | |
9 | ack is the replacement for grep! |
10 | |
11 | Here is why you should use ack over grep: http://betterthangrep.com/ |
12 | |
13 | (Now that you are sold on ack) To install ack in a one-line script: |
14 | |
15 |
|
16 | |
17 | |
18 | How to Install: |
19 | |
20 | Open a terminal and run the following: |
21 | |
22 |
|
23 | |
24 | |
25 | How to Use: |
26 | |
27 | You can use sack in exactly the same way you currently use ack! Woot! |
28 | |
29 | For why sack is faster (and more fun!) to use, read on about its main / side features... |
30 | |
31 | Main Feature 1 - Shortcuts: |
32 | |
33 | sack prefixes shortcut tags to ack's search results: |
34 | |
35 |
|
36 | |
37 | ... (omitted results) |
38 | /home/user/src/reviewboard/reviewboard/attachments/mimetypes.py |
39 | [13] 6:from djblets.util.templatetags.djblets_images import thumbnail |
40 | [14] 120: def get_thumbnail(self): |
41 | [15] 125: return mark_safe('<pre class="file-thumbnail"></pre>') |
42 | [16] 135: def get_thumbnail(self): |
43 | [17] 136: """Returns a thumbnail of the image.""" |
44 | [18] 137: return mark_safe('<img src="%s" class="file-thumbnail" alt="%s" />' |
45 | [19] 138: % (thumbnail(self.attachment.file, size='1000x1000'), |
46 | [20] 146: def get_thumbnail(self): |
47 | [21] 157: return mark_safe('<pre class="file-thumbnail">%s</pre>' |
48 | |
49 | |
50 | Now, instead of having to spend time tediously navigating to some deep directory and typing out the file name, simply do: |
51 | |
52 |
|
53 | |
54 | |
55 | And sack will open the file associated with that particular search result with your favorite editor (-cough-vim-cough-) 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) |
56 | |
57 | 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!! |
58 | |
59 | (For why removing such distractions is important to coding "in the zone", see the excellent Joel Test: http://www.joelonsoftware.com/articles/fog0000000043.html) |
60 | |
61 | Cross-Terminal Shortcuts: |
62 | |
63 | Note that whenever you perform a search in any terminal with sack, you can use the shortcuts in all other terminals (including new ones). |
64 | |
65 | 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! |
66 | |
67 | Main Feature 2 - Profiles: |
68 | |
69 | About Profiles: |
70 | |
71 | 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. |
72 | |
73 | For example: |
74 | |
75 |
|
76 | |
77 | |
78 | 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") |
79 | |
80 | Now suppose you are working under some deep directory in terminal: |
81 | |
82 |
|
83 | |
84 | |
85 | and you wanted to search the all relevant codebases to find all locations where a particular function is invoked. |
86 | |
87 | The old options were: |
88 | |
89 |
|
90 |
|
91 |
|
92 | |
93 | Now you can simply do: |
94 | |
95 |
|
96 | |
97 | |
98 | And the rest is taken care of for you. |
99 | |
100 | Note: The |
101 | |
102 | Which Profile? |
103 | |
104 | To find out which profile you are currently on: |
105 | |
106 |
|
107 | sack --whichprofile |
108 | |
109 | |
110 | Switch Profile |
111 | |
112 | To switch to a different profile ( |
113 | |
114 |
|
115 | sack --switchprofile no_profile |
116 | |
117 | |
118 | Rename Profile |
119 | |
120 | To rename the current profile: |
121 | |
122 |
|
123 | sack --renameprofile ReviewBoard |
124 | |
125 | |
126 | Set Flags |
127 | |
128 | To set new preset flags to use for the current profile: |
129 | (All searches run using this profile will use these flags) |
130 | |
131 |
|
132 | sack --setflags -ia -A 2 -B 3 |
133 | |
134 | |
135 | Set Directory |
136 | |
137 | To set new preset directory(s) to use for the current profile: |
138 | (All searches will be run under this directory with this profile) |
139 | |
140 |
|
141 | sack --setdirectory ~/src/reviewboard ~/src/rbtools ~/src/djblets |
142 | |
143 | |
144 | Add New Profile |
145 | |
146 | To add a new empty profile: |
147 | |
148 |
|
149 | sack --addnewprofile ReviewBoard |
150 | |
151 | |
152 | List Profiles |
153 | |
154 | To show the current available profiles: |
155 | |
156 |
|
157 | sack --listprofiles |
158 | |
159 | |
160 | ToDo: |
161 | |
162 | Additional features / functionalities to be implemented: |
163 | |
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
raw .md file used in screenshot | |
---|---|
1 | sack |
2 | ==== |
3 | |
4 | s(hortcut)-ack: a faster way to use ack (and grep)! |
5 | |
6 | sack acts as a wrapper for ack to provide convenience for the repetitive menial tasks |
7 | |
8 | ## What is ack? |
9 | |
10 | ack is the replacement for grep! |
11 | |
12 | Here is why you should use ack over grep: http://betterthangrep.com/ |
13 | |
14 | (Now that you are sold on ack) To install ack in a one-line script: |
15 | |
16 | curl http://betterthangrep.com/ack-standalone > ~/bin/ack && chmod 0755 !#:3 |
17 | |
18 | ## How to Install: |
19 | |
20 | Open a terminal and run the following: |
21 | |
22 | git clone git@github.com:sampson-chen/sack.git && cd sack && chmod +x install_sack.sh && ./install_sack.sh |
23 | |
24 | ## How to Use: |
25 | |
26 | You can use sack in exactly the same way you currently use ack! Woot! |
27 | |
28 | For why sack is faster (and more fun!) to use, read on about its main / side features... |
29 | |
30 | ## Main Feature 1 - Shortcuts: |
31 | |
32 | sack prefixes shortcut tags to ack's search results: |
33 | |
34 | user@linux:~/src$ sack thumbnail |
35 | |
36 | ... (omitted results) |
37 | /home/user/src/reviewboard/reviewboard/attachments/mimetypes.py |
38 | [13] 6:from djblets.util.templatetags.djblets_images import thumbnail |
39 | [14] 120: def get_thumbnail(self): |
40 | [15] 125: return mark_safe('<pre class="file-thumbnail"></pre>') |
41 | [16] 135: def get_thumbnail(self): |
42 | [17] 136: """Returns a thumbnail of the image.""" |
43 | [18] 137: return mark_safe('<img src="%s" class="file-thumbnail" alt="%s" />' |
44 | [19] 138: % (thumbnail(self.attachment.file, size='1000x1000'), |
45 | [20] 146: def get_thumbnail(self): |
46 | [21] 157: return mark_safe('<pre class="file-thumbnail">%s</pre>' |
47 | |
48 | Now, instead of having to spend time tediously navigating to some deep directory and typing out the file name, simply do: |
49 | |
50 | user@linux:~$ F 21 |
51 | |
52 | And sack will open the file associated with that particular search result with your favorite editor (-cough-vim-cough-) 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) |
53 | |
54 | 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!! |
55 | |
56 | (For why removing such distractions is important to coding "in the zone", see the excellent Joel Test: http://www.joelonsoftware.com/articles/fog0000000043.html) |
57 | |
58 | ### Cross-Terminal Shortcuts: |
59 | |
60 | Note that whenever you perform a search in any terminal with sack, you can use the shortcuts in all other terminals (including new ones). |
61 | |
62 | 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! |
63 | |
64 | ## Main Feature 2 - Profiles: |
65 | |
66 | About Profiles: |
67 | |
68 | 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. |
69 | |
70 | For example: |
71 | |
72 | user@linux:~$ sack -sp RB |
73 | |
74 | 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") |
75 | |
76 | Now suppose you are working under some deep directory in terminal: |
77 | |
78 | user@linux:~/src/reviewboard/reviewboard/reviews/management/commands/diffs$ |
79 | |
80 | and you wanted to search the all relevant codebases to find all locations where a particular function is invoked. |
81 | |
82 | The old options were: |
83 | |
84 | - cd to ~/src/, run ack there, and then later cd back to ~/src/reviewboard/reviewboard/reviews/management/commands/diffs$ (arggggghh!!!) |
85 | - typing out this on the prompt: ack -i pattern1 ~/src/reviewboard/ ~/src/rbtools ~/src/djblets |
86 | - opening a new terminal to run ack |
87 | |
88 | Now you can simply do: |
89 | |
90 | user@linux:~/src/...//.../diffs$ sack pattern1 |
91 | |
92 | And the rest is taken care of for you. |
93 | |
94 | Note: The `no_profile` profile is special: it never uses any preset flags or search directories. sack behaves exactly like ack while under `no_profile` (except for the shortcuts) |
95 | |
96 | ### Which Profile? |
97 | |
98 | To find out which profile you are currently on: |
99 | |
100 | sack -wp |
101 | sack --whichprofile |
102 | |
103 | ### Switch Profile |
104 | |
105 | To switch to a different profile (`no_profile` is the empty profile): |
106 | |
107 | sack -sp PROFILE_NAME |
108 | sack --switchprofile no_profile |
109 | |
110 | ### Rename Profile |
111 | |
112 | To rename the current profile: |
113 | |
114 | sack -rp NEW_PROFILE_NAME |
115 | sack --renameprofile ReviewBoard |
116 | |
117 | ### Set Flags |
118 | |
119 | To set new preset flags to use for the current profile: |
120 | (All searches run using this profile will use these flags) |
121 | |
122 | sack -sf NEW_FLAGS |
123 | sack --setflags -ia -A 2 -B 3 |
124 | |
125 | ### Set Directory |
126 | |
127 | To set new preset directory(s) to use for the current profile: |
128 | (All searches will be run under this directory with this profile) |
129 | |
130 | sack -sd DIRECTORY_1 DIRECTORY_2 DIRECTORY_3 |
131 | sack --setdirectory ~/src/reviewboard ~/src/rbtools ~/src/djblets |
132 | |
133 | ### Add New Profile |
134 | |
135 | To add a new empty profile: |
136 | |
137 | sack -anp PROFILE_NAME |
138 | sack --addnewprofile ReviewBoard |
139 | |
140 | ### List Profiles |
141 | |
142 | To show the current available profiles: |
143 | |
144 | sack -lp |
145 | sack --listprofiles |
146 | |
147 | ## ToDo: |
148 | |
149 | Additional features / functionalities to be implemented: |
150 | |
151 | - Implement support for other editors (emacs, sublimeText etc) |
152 | - Implement high-light for vim for the searchword when following a shortcut |
153 | - Functionality for deleting a profile |
154 | - Check that the user has ~/bin in their path |
155 | - Add a check in `install_sack.sh` to also install ack if it's not already on the system. |
156 | - Finish implementation for a decrement count for the beginner msg so it displays a certain number of times at the start |
157 | - (Suggest a feature that you want for sack!) |