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