PRIMARY CATEGORY → SETUP
ZSH → Z Shell
This shell is prefered over bash or fish because of all the handy functionalities and customisation It offers to the users
It implements handy features such as →
Advanced Autocomplete ~ Autosuggestions ~ Syntactical Corrections ~ Advanced Globbing
Shared History between different terminals ~ Syntax Highlighting
Main File → ~/.zshrc
Source File → ~/.config/zsh/src/custom.zsh
Theme’s Configuration File (Powerlevel10k) → ~/.p10k.zsh
More info here and in the ZSH Manual
Plugins
Most of the above features can be implemented or enhanced through ZSH Plugins that are sourced from the .zshrc
configuration file
The .zsh files related to the plugins below are sourced from the
.zshrc
configuration file
ZSH-autocomplete
It enhances the ZSH’s inherent auto-complete capability
.zsh file is sourced from .zshrc
ZSH-autosuggestions
It suggests commands as the user types based on history and the previous completions
.zsh file is sourced from .zshrc
ZSH-syntax-highlighting
It enables highlighting of commands while typing them in an interactive terminal
.zsh file is sourced from .zshrc
Dracula Theme
There are different themes for this plugin, the one used in this setup enviroment is the Dracula Theme
To use it, just source
, in the .zshrc
file, the .zsh script resulting from the steps in the link above
IMPORTANT
Note that the
dracula.zsh
script should only be sourced if the zsh-syntax-highlighting’s script has been sourced correctly previouslyThe above action is performed in the ZSH Custom Configuration File. It implements something like this →
ZSH-sudo
This plugins automatically places the sudo binary at the beginnng of the line by pressing the Esc
key twice
.zsh file is sourced from .zshrc
Installation
CAUTION
User’s Default Shell
To change the users’ default shell to a ZSH one, as Root →
Plugins
Plugins’ Path →
/usr/share/ZSH_PLUGIN_NAME
To install most of the plugins → Autocomplete ~ Autosuggestions ~ Syntax-hightlighting
INFO
In this Environment Setup, the only ZSH Plugins to be used are ZSH-Syntax-highlighting and ZSH-Sudo
ZSH-Sudo
As Root, Install the ZSH-Sudo Plugin, as follows →
ZSH-Syntax-Highlighting
It has been previously installed via apt
in the /usr/share/zsh-syntax-highlighting/
As mentioned in the ZSH-Syntax-Highlighting Plugin’s Section, the Theme selected for this plugin is the Dracula Theme
Install the above Syntax Theme as follows →
CAUTION
Note that the
dracula.zsh
script should only be sourced if the zsh-syntax-highlighting’s script has been sourced correctly previouslySee the Dracula theme Section for more information about the Source Code Block
Theme
The ZSH Theme to install → Powerlevel10k
IMPORTANT
Note that the following steps related to the ZSH Theme’s Installation should be applied for both non-privileged and privileged users
Being in this case for Root and al3xbb
Manual installation as follows →
To source the powerlevel10k script , insert this line at the beginning of the .zshrc
file →
Then, to start the interactive powerlevel10k’s setup →
Hack Nerd Fonts’s previous installation is required. See here
Do not forget to repeat the above steps for the other users
To set up a more granular configuration, just edit the .p10k.zsh file as follows →
.p10k.zsh - Modified Sections
In that powerlevel10k file, for this Setup Enviroment, as the non-privileged user, add/edit as follows →
- Left Prompt Elements
- Righ Prompt Elements → All of them should be commented as in the configuration file
Regarding to the dir segment, the bold font can be disabled as follows →
Repeat all the above steps as Root
Only as Root, add/edit as follows to add an icon as a context→
.ZSHRC File
Symbolic Link
To avoid having to modify, when a change is made, both the Root and the Non-privileged User’s .zshrc file, simply proceed as follows →
As Root
INFO
Above command just creates a symbolic link as
~/.zshrc
which points to/home/al3xbb/.zshrc
Therefore, any changes made to the .zshrc file apply to both users
ZSH Plugins
As mentioned in the Plugins’ Section, each Plugin’s .zsh script must be sourced from the .zshrc
file
In this environment setup, the sourced ones are → zsh-syntax-highlighting ~ zsh-sudo
Check if exist and source them →
- ZSH-Sudo
- ZSH-Syntax-Highlighting → 🦇 Dracula Theme 🧛🏻♂️
ZSH Plugin and Plugin’s Theme sourced
Configuration File
ZSH
.zshrc
ZSH Configuration File → .zshrc
src/custom.zsh
ZSH Source File → custom.zsh
Powerlevel10k
.p10k.zsh
Non-Privileged User’s Powerlevel10k Configuration File → .p10k.zsh
Root’s Powerlevel10k Configuration File →.p10k.zsh
Parameters
Z Shell ~ .zshrc
PATH
PATH Enviromental Parameter
In addition to the usual paths such as /usr/bin:/bin:/usr/sbin:/usr/local/bin
, others are added →
This allows to use their binaries from any path relatively
Aliases
Various aliases are defined to carry out the following sustitutions →
batcat
rather thancat
lsd
rather thanls
To remove the lsd
’s Bold applied to the font and file icons, just declare the LS_COLORS
parameter as It appears in the .zshrc configuration file
Command History
Command History File → .zsh_history
Command History File’s Size → Number of entries in .zsh_history
Command History’s Memory entries → Number of entries in the History Memory
To ignore duplicate entries in the Command History and Synchronise it between the open terminals →
Command Line Editor
Use the following ZSH Builints to enable the Command Line Editor →
The above code ensures that the Command Line Editor can be accessed through C-x C-e
as in bash
IMPORTANT
Note that the edit-command-line ZSH Function opens the Command Line Editor with the text editor set as value in the EDITOR parameter
It is necessary to stablish the Text Editor used in the Command Line Editor
This is carried out through the EDITOR
parameter
Editor → Neovim
This is extremely useful when e.g. doing
C-x C-e
to open the Command Line Editor
Autocompletion System
To enable the ZSH’s Modern Autocompletion System →
INFO
The above command deferred loads the ZSH’s compinit function and, if true, calls it
Note that the
-U
option causes its function reference to not be loaded into the ZSH Hash TableWhile the
-z
option only checks that the function provided as an argument is strictly for ZSH
If the compinit
function is loaded and called correctly, then various additional configurations are applied to the ZSH Autocompletion System
These can be found in the .zshrc configuration file
FZF - Fuzzy Finder
This Fuzzy Finder is mainly used to modify the C-r
Shell’s shortcut for reverse history search
To load all FZF Functionality and Shortcuts in the ZSH Process Context →
Then, to enable some FZF’s handy features →
JAVA Troubleshooting
There are Windows Managers, such as bspwm, that do not perform any Windows Reparenting
Therefore, any Java Application that uses JWT, may experience some integration problems in an environment with these Windows Managers
In order to avoid the previous problems →
The above code simply tells Java to carry out the Windows Reparenting instead of the Windows Manager
IMPORTANT
Note that, in addition to the above measure, another is implemented in the bspwmrc
This changes the current Windows Manager’s name, which the System recognises, to LG3D
LG3D is an old Windows Manager, and the Java Applications created with JWT run correctly on it
So changing the Windows Manager’s Name tricks Java into thinking It is running in a supported environment
Custom Functions
All the Custom Functions related to the .zshrc file are sourced from the custom.zsh script
There are several handy functions such as →
- clearScreenAndScrollback → Reference
The remaining functions are related to the Pentesting Index Category
Powerlevel10k ~ .p10k.zsh
This ZSH Theme is extremely customizable
The basic units are the segments, which display specific information from different sources at the user’s prompt
The segments can be located in the left or right side (i.e. the left or right prompt)
In this environment setup, only those on the right are enabled →
OS_ICON
INFO
Note that the below code snippets are related to the .p10.zsh file
It displays the Operative System Icon
To enable it →
To modify the displayed icon and its colour →
DIR
It displays the Current Work Directory
To enable it →
Note how the Current Work Directory changes continously
VCS
If the Current Work Directory is a Github Repository, It displays de Git Status
See → “on😺🌿master”
CONTEXT
In this case, if someone is connected to other host remotely, It shows the current user and hostname
See → “with test@parrot”
COMMAND_EXECUTION_TIME
It displays the last command’s time duration, from a sleep
command to an SSH Session
See → “Took⌛12s”
STATUS
It displays the Exit Code of the last command
See → “❌127/1/INT/TSTP ~ ✅1”