UNPKG

12.2 kBMarkdownView Raw
1# Bash Profile by Nasc
2
3Easy to customize, built on top of the power of JavaScript and Bash, it ads a bunch of _aliases_, functions, features and extra funcionality for your bash profile.
4
5![termtools themes](media/termtools-built-in-themes.png)
6
7## Features
8
9- [x] Fully customizable using **JavaScript**
10- [x] Applies to PS1
11- [x] Terminal comands to enable or disable it (restoring your previous PS1)
12- [x] Allows you to dinamically _turn on_ and _off_ parts of PS1
13- [x] PS2 with line numbers
14- [x] Auto completes git commands
15- [x] Shows current **branch** and git **state** (also customizable)
16- [x] Lots of Extra **aliases** (check the aliases section for more info about it)
17- [x] Extra **functions**
18- [x] Suport **themes** (coming with 6 themes for you to extend and customize...[see below](#Themes))
19- [x] Move easily from one theme to another
20- [x] **Protects** some actions (like deleting or change permissions to root path)
21- [x] Auto installs **fonts** for you (although, you might need to select them in your terminal settings)
22- [x] Ensures colors...everywhere... _grep_, _git_, _ls_...
23- [x] More tools, like time, battery and readOnly...
24- [x] Extendable...you can customize your theme with any extra string, allowing you to use JavaScript to decide what to show
25
26![Termtools with battery, time and read only](media/termtools-theme-default-with-battery.jpg)
27
28## Installing it
29
30Easy like sunday morning!
31
32```
33npm install -g @nasc/termtools
34```
35
36## Applying it
37
38Run this command and, if everything went well, your terminal should be good looking by now!
39
40```
41termtools apply
42```
43
44## Oh Oh!
45
46Seing _weird characters_? No worries, follow the tips your own terminal will give you.
47At any time, you can run `termtools check` to validate the characters and some colors.
48
49The font we are using (and was already installed for you) is:
50**"Droid Sans Mono for Powerline Plus Nerd File Types Mono"**
51
52All you gotta do is go to your terminal settings, and edit your profile changint its font family/face to that one.
53
54In _Visual Studio Code_, you can add the settings for the integrated terminal:
55
56```
57"terminal.integrated.fontFamily": "Droid Sans Mono for Powerline Plus Nerd File Types Mono"
58```
59
60You should be able to run `termtools check` and see this message:
61
62![Termtools character set test](media/character-set-check.png)
63
64## Removing it (restore)
65
66Want to see the your PS1 as it was before (will also loos all the _aliases_ and extra functions).
67
68```sh
69termtools remove
70# or
71termtools restore
72```
73
74To bring it back, just run the `apply` command again:
75
76```
77termtools apply
78```
79
80## Reloading it
81
82After installed and applied, you have three ways to reload it. Both ways will reload the whole bash profile (applying any updates that might be outdated).
83
84```sh
85# alternative 1
86termtools reload
87#alternative 2
88reload
89# alternative 3
90termtools restore
91termtools apply
92```
93
94## Git integration
95
96If you are navigating in a directory that happens to belong to a Git Repository, you will see its current branch in your terminal.
97Also, the color indicates the current status of your branch, there you might see symbols identifying your branch as _behind_, _ahead_ or _diverged_.
98
99![Termtools default theme](media/termtools-theme-default-git.png)
100
101### PS2
102
103We also change your PS2 a little, adding line numbers for your multiple lined commands:
104
105![Termtools multiline commands with line numbers](media/termtools-theme-default-multi-line.png)
106
107## Customizing
108
109You can customize it using **JavaScript** \o/
110And it is not even a _JSON_, nope...it is JavaScript, indeed.
111
112We can create a boilerplate for you to customize (a copy of the default settings).
113Just run:
114
115```
116termtools customize
117```
118
119It will create a file at **`~/.basch_profile.js`**.
120That file is a copy of our _default_ theme, with comments and all you might need to extend it.
121This JavaScript file **must** export a literal object, or a function that resolves to a literal object.
122
123If you exported a function, it will be called, receiving one parameter, an object with these properties:
124
125- IS_TTY: True if current session is running on a TTY environment
126- IS_ROOT: True if the current user is root
127- IP: The current device's ip
128- BATTERY: The current percentage of the battery (give or take...some OSs lie a little about it)
129- IS_CHARGING: True if the device is connected and charging
130- GIT_STATUS: The repository status. May be from -2 to 5, meaning:
131 * -2: COMMITS DIVERGED
132 * -1: COMMITS BEHIND
133 * 0: NO CHANGES
134 * 1: COMMITS AHEAD
135 * 2: UNTRACKED CHANGES
136 * 3: CHANGES TO BE COMMITTED
137 * 4: LOCAL AND UNTRACKED CHANGES
138 * 5: LOCAL CHANGES
139- GIT_SYMBOL: A symbol representing the current position of the branch. Symbols can be:
140 * "-": COMMITS BEHIND
141 * "+": COMMITS AHEAD
142 * "!": COMMITS DIVERGED
143 * "*": UNTRACKED
144 * "": Anything else
145- GIT_BRANCH: The name of the current branch
146- IS_WRITABLE: True if the current user has write access to the current directory
147- colors: A referece to the a `chalk` instance, allowing you to add colors if you need to
148
149Use these data to decide how your exported object will be. You can use it, for example, to enable or disable parts of the PS1, or to show some parts in different colors.
150
151Check the documentation bellow to understand it better, how to customize your terminal using JavaScript.
152
153 > After any change you make in your customized theme, you should see the difference just by hitting [ENTER] in your terminal.
154 If not...you can force it to reload using `termtools reload` or just the elias `reload`.
155
156### Customization options
157
158You will export a _literal object_ containing these options, or a function that returns such an object.
159You can extend a given theme, or the default theme will be used.
160
161```js
162{
163 extends: 'basic'
164}
165```
166
167While the default theme will have a _PS1_ like the first image in this documentation, the basic theme will look like this:
168
169![Termtools basic theme](media/termtools-theme-basic.jpg)
170
171#### aliases
172
173An object containing the _command_ as the key, and the _instruction_ as the value.
174For example:
175
176```js
177{
178 aliases: {
179 foo: "echo bar"
180 }
181}
182```
183
184Will then, allow you to run in your terminal:
185
186```sh
187$ foo
188bar
189```
190
191#### Decorators
192
193You can remove/comment them from your custom settings if you want to keep it cleaner.
194This will allow you to customize some of the decorators we will use in your PS1.
195So far, they are:
196
197- pathSeparator
198- section
199- git
200
201You can use the code (`\uCODE`) for the following characters (available in the installed font).
202For example, the code "e0a0" can be used as `"\ue0a0"`:
203
204![Termtool fontforge](media/fontforge.png)
205(imported from https://github.com/ryanoasis/powerline-extra-symbols)
206
207#### ps1
208
209This is the part where you specify the rules for your PS1.
210It has two customization options: `parts` and `effects`.
211The effects are the style rules, applied for each part.
212
213##### Parts
214
215Every part of your PS1 has the `enabled` flag, allowing you to turn them on or off as you will.
216Besides that, all the properties also accept a `wrapper`, which is a string with a "$1". For example, in the "username", the wrapper "[$1]" for the user "felipe" becomes "[felipe]"
217The available parts and their attributes special attributes are:
218
219| Part name | Description | Extra options |
220| battery | Shows the current battery state | |
221| time | The current time | |
222| userName | The currently logged user | |
223| string | Any given string you might wanna add | content: The content of the string |
224| machine | The machine name | |
225| path | The current path (without basename) | *Options escribed bellow |
226| basename | The current basename | |
227| git | If the current directory is a repository, show the git information about it |
228| entry | The last character waiting for the user entry. Usually a "$" sign | content: A given string for it |
229| readOnly | Shown when the current directory is readonly for the current user | |
230
231##### Effects
232
233For each part you used, you can apply effects.
234The available effects are:
235
236- color*: The text color
237- bgColor*: The background color
238- bold: Sets text as bold
239- italic: Tries to set the text as italic (not all terminals support it)
240- underline: Underlines the text
241- dim: Sets the text as dim
242- separator: By default, will be the decorator you set as separator. If false, no separator will be used for that part. Can be used to customize the separator of one specific part of PS1
243
244 > Values for both `color` and `bgColor` accept the colors from [chalk](https://github.com/chalk/chalk). You can also use _RGB_ colors starting with "#", for example `#f00`. But keep in mind that some hex values are not supported in some terminals.
245
246#### Themes
247
248Yes, we deliver _termtools_ with 6 builtin themes, they are:
249
250- basic
251- default
252- hell
253- sea
254- pinkish
255- round
256
257You can easily move from one theme to another using the command
258
259```
260termtools set theme [theme-name]
261```
262
263Just be careful! It will replace your `~/.bash_profile.js` and, if you have done any customization to it, you will loose them.
264
265 > If you have created a very nice theme and want to share, send us a pull request :)
266
267### Aliases
268
269- fixcamera: Fixes the camera when it is not loading (a known bug triggered in Google Chrome)
270- ipin: Shows the internal IP addess
271- ipout: Shows the IP facing the public network
272- ip: Shows both internal and external IPs
273- aliases: Shows the list of currently supported aliases
274- back: Goes to the last path where you were
275- ..: Equivalent to `cd ..`
276- cd..: Equivalent to `cd ..`
277- .2: Equivalent to `cd ../..`
278- .3: Equivalent to `cd ../../..`
279- .4: Equivalent to `cd ../../../..`
280- .5: Equivalent to `cd ../../../../..`
281- .6: Equivalent to `cd ../../../../../..`
282- .7: Equivalent to `cd ../../../../../../..`
283- ll: A better listing of your files and directories
284- ~: Goes to your HOME directory
285- root: Goes to your root path (/)
286- www: Goes to `/var/www/`
287- commit: `git commit -a`
288- commitAll: `git add -A; git commit`
289- gitlog: Shows a more readable log for your git repo
290- gittree: Shows a readable tree for your git repo
291- checkout: `git checkout`. Used as `checkout mybranch`.
292- push: `git push origin`. Use it like `push master`.
293- pull: `git pull origin`
294- sizes: Shows the size of your files and directories
295- flushDNS: Flushes the DNSs
296- DSFiles_removal: Removes all the `.DS_Store` files (recursivelly) in the current tree
297- hosts_editir: Opens and editor for your hosts file
298- h: Shows the bash history
299- today: Shows the date for today
300- now: Shows the current time
301- ports: Shows the currently pened ports
302- lsd: Equivalent to `ls` but showing only directories
303- extract: Extracts any compressed files (works with any file with extension tar.bz2, tar.gz, bz2, rar, gz, tar, tbz2, tgz, zip, Z, 7z)
304- pid: Shows the PID for a given process name
305- about: Shows info on the current serve/session/user
306- targz: Create a .tar.gz archive, using `zopfli`, `pigz` or `gzip` for compression
307- googl/short: Shortens a URL using goo.gl service
308- sizeof: Gives you the size of a file, or the total size of a directory
309- hierarchy: Shows a tree of files ignoring `node_modules` and other temp files, using line numbers, pages and colors.
310- hide-desktop-icons: Hide all the desktop icons (specially useful when presenting to an audience)
311- show-desktop-icons: show all desktop icons
312- chromekill: Kills all Google Chrome tabs to free some memory
313- afk: Locks the screen, as you are Away From Keyboard
314- path: Shows all the address in your `$PATH`, each one in a different line
315- show-hidden-files: Show hidden files (MacOS only)
316- hide-hidden-files: Hide hidden files (MacOS only)
317- dog: Just like cat, but paginated and using line numbers
318- ifactive: Shows all the active network connections
319- amioffline: Answers "Yes" if you are offline, and "No" otherwise
320- amionline: Answers "Yes" if you are online, and "No" otherwise
321- desktop/desk: Equivalent to `cd ~/Desktop`
322- docs/d/documents: Equivalent to `cd ~/Documents`
323- downloads/down: Equivalent to `cd ~/Downloads`
324- line: Writes a line (-) in terminal
325- doubleline: Writes a double line (=) in terminal
326- bold: Like `echo`, but outputs the text in _bold_.
327
328