content/blog/2022-07-31-bash-it.org
242 lines · 7844 bytes
1#+date: <2022-07-31 Sun 00:00:00>
2#+title: Enhancing Bash Shell Functionality with Bash-It and ble.sh Plugins
3#+description: Guide to augmenting Bash shell features by integrating Bash-It framework along with ble.sh for input autosuggestions, improving command-line efficiency on Linux systems.
4#+slug: bash-it
5#+filetags: :bash:shell:linux:
6
7* Bash
8
9For those who are not familiar,
10[[https://en.wikipedia.org/wiki/Bash_(Unix_shell)][Bash]] is a Unix
11shell that is used as the default login shell for most Linux
12distributions. This shell and command processor should be familiar if
13you've used Linux (or older version of macOS) before.
14
15However, bash is not the only option. There are numerous other shells
16that exist. Here are some popular examples:
17
18- [[https://en.wikipedia.org/wiki/Z_shell][zsh]]
19- [[https://en.wikipedia.org/wiki/Fish_(Unix_shell)][fish]]
20- [[https://github.com/ibara/oksh][oksh]]
21- [[https://wiki.gentoo.org/wiki/Mksh][mksh]]
22- [[https://en.wikipedia.org/wiki/Debian_Almquist_shell][dash]]
23
24While each shell has its differences, bash is POSIX compliant and the
25default for many Linux users. Because of this, I am going to explore a
26program called =bash-it= below that helps bash users increase the
27utility of their shell without installing a completely new shell.
28
29** Installation
30
31First, if bash is not already installed on your system, you can
32[[https://www.gnu.org/software/bash/][download bash from GNU]] or use
33your package manager to install it.
34
35For example, this is how you can install bash on Fedora Linux:
36
37#+begin_src sh
38sudo dnf install bash
39#+end_src
40
41If you are not using bash as your default shell, use the =chsh= command
42to change your shell:
43
44#+begin_src sh
45chsh
46#+end_src
47
48You should see a prompt like the one below. If the brackets (=[]=)
49contain =bash= already, you're done, and you can simply continue by
50hitting the Enter key.
51
52If the brackets contain another shell path (e.g. =/usr/bin/zsh=), enter
53the path to the bash program on your system (it's most likely located at
54=/usr/bin/bash=).
55
56#+begin_src sh
57Changing shell for <user>.
58New shell [/usr/bin/bash]:
59#+end_src
60
61You must log out or restart the machine in order for the login shell to
62be refreshed. You can do it now or wait until you're finished
63customizing the shell.
64
65#+begin_src sh
66sudo reboot now
67#+end_src
68
69* Bash-it
70
71As noted on the [[https://github.com/Bash-it/bash-it][Bash-it]]
72repository:
73
74#+begin_quote
75Bash-it is a collection of community Bash commands and scripts for Bash
763.2+. (And a shameless ripoff of oh-my-zsh 😃)
77#+end_quote
78
79Bash-it makes it easy to install plugins, set up aliases for common
80commands, and easily change the visual theme of your shell.
81
82** Installation
83
84To install the framework, simply copy the repository files and use the
85=install.sh= script provided. If you want, you can (and should!) inspect
86the contents of the installation script before you run it.
87
88#+begin_src sh
89git clone --depth=1 https://github.com/Bash-it/bash-it.git ~/.bash_it
90~/.bash_it/install.sh
91#+end_src
92
93If you didn't restart your session after making bash the default, and
94are currently working within another shell, be sure to enter a bash
95session before using =bash-it=:
96
97#+begin_src sh
98bash
99#+end_src
100
101** Aliases
102
103Bash-it contains a number of aliases for common commands to help improve
104efficiency in the terminal. To list all available options, use the
105following command:
106
107#+begin_src sh
108bash-it show aliases
109#+end_src
110
111This will provide you a list that looks like the following text block.
112Within this screen, you will be able to see all available options and
113which ones are currently enabled.
114
115#+begin_src txt
116Alias Enabled? Description
117ag [ ] the silver searcher (ag) aliases
118ansible [ ] ansible abbreviations
119apt [ ] Apt and dpkg aliases for Ubuntu and Debian distros.
120atom [ ] Atom.io editor abbreviations
121bash-it [ ] Aliases for the bash-it command (these aliases are automatically included with the "general" aliases)
122bolt [ ] puppet bolt aliases
123bundler [ ] ruby bundler
124clipboard [ ] xclip shortcuts
125composer [ ] common composer abbreviations
126curl [x] Curl aliases for convenience.
127...
128#+end_src
129
130To enable an alias, do:
131
132#+begin_src sh
133bash-it enable alias <alias name> [alias name]... -or- $ bash-it enable alias all
134#+end_src
135
136To disable an alias, do:
137
138#+begin_src sh
139bash-it disable alias <alias name> [alias name]... -or- $ bash-it disable alias all
140#+end_src
141
142** Plugins
143
144Similar to aliases, plugins are available with bash-it. You can find a
145complete list of plugins in the same way as aliases. Simply execute the
146following:
147
148#+begin_src sh
149bash-it show plugins
150#+end_src
151
152You will see the following output showing enabled and disabled plugins:
153
154#+begin_src txt
155Plugin Enabled? Description
156alias-completion [ ]
157autojump [ ] Autojump configuration, see https://github.com/wting/autojump for more details
158aws [ ] AWS helper functions
159base [x] miscellaneous tools
160basher [ ] initializes basher, the shell package manager
161battery [x] display info about your battery charge level
162blesh [ ] load ble.sh, the Bash line editor!
163boot2docker [ ] Helpers to get Docker setup correctly for boot2docker
164browser [ ] render commandline output in your browser
165#+end_src
166
167To enable a plugin, do:
168
169#+begin_src sh
170bash-it enable plugin <plugin name> [plugin name]... -or- $ bash-it enable plugin all
171#+end_src
172
173To disable a plugin, do:
174
175#+begin_src sh
176bash-it disable plugin <plugin name> [plugin name]... -or- $ bash-it disable plugin all
177#+end_src
178
179** Themes
180
181There are quite a few pre-defined
182[[https://bash-it.readthedocs.io/en/latest/themes-list/#list-of-themes][themes]]
183available with bash-it.
184
185To list all themes:
186
187#+begin_src sh
188ls ~/.bash_it/themes/
189#+end_src
190
191To use a new theme, you'll need to edit =.bashrc= and alter the
192=BASH_IT_THEME= variable to your desired theme. For example, I am using
193the =zork= theme.
194
195#+begin_src sh
196nano ~/.bashrc
197#+end_src
198
199#+begin_src sh
200export BASH_IT_THEME='zork'
201#+end_src
202
203Once you save your changes, you just need to exit your terminal and
204create a new one in order to see your changes to the =.bashrc= file. You
205can also =source= the file to see changes, but I recommend starting a
206completely new shell instead.
207
208*** ble.sh
209
210One big feature I was missing in Bash that both =zsh= and =fish= have is
211an autosuggestion feature. To explain: as you type, an autosuggestion
212feature in the shell will offer suggestions in a lighter font color
213beyond the characters already typed. Once you see the command you want,
214you can click the right arrow and have the shell auto-complete that line
215for you.
216
217Luckily, the [[https://github.com/akinomyoga/ble.sh][Bash Line Editor]]
218(ble.sh) exists! This program provides a wonderful autosuggestions
219feature perfectly, among other features that I haven't tested yet.
220
221In order to install ble.sh, execute the following:
222
223#+begin_src sh
224git clone --recursive https://github.com/akinomyoga/ble.sh.git
225make -C ble.sh install PREFIX=~/.local
226echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc
227#+end_src
228
229Again, exit the terminal and open a new one in order to see the
230newly-configured shell.
231
232* Restart the Session
233
234Finally, as mentioned above, you'll need to restart the session to
235ensure that your user is using bash by default.
236
237You will also need to exit and re-open a shell (e.g., terminal or
238terminal tab) any time you make changes to the =.bashrc= file.
239
240#+begin_src sh
241sudo reboot now
242#+end_src