Configuración y tuneo de entorno Linux ZSH

Voy a pasar a describir cómo configuro mi entorno de debian con la configuracion de zsh, despues de la instalación. Es muy simplona pero me sirve para lo que uso.

En esta configuración voy a usar zsh y las siguientes utilidades:

oh-my-zsh -> para poder personalizar un poco el theme y plugins

lsd -> es un ls pero más bonito que colorea

batcat -> es un cat pero que muestra más cómodos los datos

para empezar voy a partir de una distro nueva recién instalada (Debian)

vamos instalar primero el ZHS

apt-get update && apt-get install zsh

y lo siguiente es asignar la zsh al root

chsh root -s /bin/zsh

Ahora vamos a crear el usuario que necesito

lo primero es implementar el sudo

apt-get install sudo

después creamos el usuario:

useradd -m -G sudo -s /bin/zsh guiskas

-m crea la carpeta en home

-G sudo añade al usuario como grupo secundario en sudo

-s /bin/zsh le decimos que use en shell de zsh

ahora le ponemos una contraseña

 passwd guiskas

con esto podemos ya arrancar con nuestro nuevo usuario , cerramos el terminal con exit y lo arrancamos con nuestro usuario

Si se da el caso que ya tenemos creado el usuario usamos este comando para cambiar el shell:

chsh -s $(which zsh)

Una vez arrancado nos saldrá el siguiente texto :

This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).

--- Type one of the keys in parentheses ---

pulsamos la tecla 0 y salimos al shell si pulsas el CTRL+L limpiamos la ventana .

ahora vamos a instalar el oh-my-zsh y sus plugins

lo primero instalamos git y wget

sudo apt-get install git wget unzip feh

y después ejecutamos :

sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

veremos que nos sale este texto y lo tendremos listo :

Cloning Oh My Zsh...
remote: Enumerating objects: 1297, done.
remote: Counting objects: 100% (1297/1297), done.
remote: Compressing objects: 100% (1254/1254), done.
remote: Total 1297 (delta 26), reused 1210 (delta 24), pack-reused 0
Receiving objects: 100% (1297/1297), 1.06 MiB | 9.00 MiB/s, done.
Resolving deltas: 100% (26/26), done.
From https://github.com/ohmyzsh/ohmyzsh
 * [new branch]      master     -> origin/master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Already on 'master'
/home/guiskas

Looking for an existing zsh config...
Found ~/.zshrc. Backing up to /home/guiskas/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to ~/.zshrc.

         __                                     __
  ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/                       ....is now installed!


Before you scream Oh My Zsh! look over the `.zshrc` file to select plugins, themes, and options.

• Follow us on Twitter: https://twitter.com/ohmyzsh
• Join our Discord community: https://discord.gg/ohmyzsh
• Get stickers, t-shirts, coffee mugs and more: https://shop.planetargon.com/collections/oh-my-zsh

➜  ~
source ~/.zshrc

a partir de aquí hay que instalar una serie de plugins y modificar el archivo de configuración de la zsh

primero vamos a instalar el autosuggestion que nos ayuda con la sintaxis

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

después el plugin de syntax-highlighting. para colorear el textos .

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

Ahora solo queda instalar un par de aplicaciones que me gustan que son la s arriba mencionadas :

Primero LSD, nos vamos a la página de github de Peltoche y en su repositorio LSD buscamos la ultima release y descargarmos . https://github.com/Peltoche/lsd/releases

en mi caso el la 0.21.0

wget https://github.com/Peltoche/lsd/releases/download/0.21.0/lsd_0.21.0_amd64.deb

y lo instalamos

sudo dpkg -i lsd_0.21.0_amd64.deb

y hacemos lo mismo con el batcat de Sharkdp https://github.com/sharkdp/bat/releases

wget https://github.com/sharkdp/bat/releases/download/v0.21.0/bat_0.21.0_amd64.deb

y lo instalamos

sudo dpkg -i bat_0.20.0_amd64.deb

los siguiente que vamos a hacer es instalar una de las tipografias que tenemos en https://www.nerdfonts.com/

La instalación de la tipografía nos interesa sobretodo si configuramos ZSH para ser usado sobre hardware o en máquina virtual. Si estamos usando directamente SSH por que tenemos un vps o similar, esta configuración hay que hacerla en el programa que usemos para entrar (putty, mobaxterm o similar).

en mi caso voy a usar la hack y la instalamos en /usr/local/share/fonts (en mi caso esta ruta no existe)

wget https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Hack.zip
unzip Hack.zip
sudo mkdir /usr/local/share/fonts/ 
sudo mv *.ttf /usr/local/share/fonts
fc-cache -f -v

o también podemos usar :

sudo apt-get install fonts-hack-ttf

Instalamos el Fuzzy finder:

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

marcamos la siguientes opciones

Downloading bin/fzf ...
  - Already exists
  - Checking fzf executable ... 0.34.0
Do you want to enable fuzzy auto-completion? ([y]/n) n
Do you want to enable key bindings? ([y]/n) y

Generate /home/guiskas/.fzf.bash ... OK
Generate /home/guiskas/.fzf.zsh ... OK

Do you want to update your shell configuration files? ([y]/n) y

Update /home/guiskas/.bashrc:
  - [ -f ~/.fzf.bash ] && source ~/.fzf.bash
    - Already exists: line #120 

Update /home/guiskas/.zshrc:
  - [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
    - Already exists: line #143 

Finished. Restart your shell or reload config file.
   source ~/.bashrc  # bash
   source ~/.zshrc   # zsh

Use uninstall script to remove fzf.

For more information, see: https://github.com/junegunn/fzf

Ahora lo ultimo que vamos hacer es instalar la PoerLevel10K que es una aplicación que nos customiza el prompt: https://github.com/romkatv/powerlevel10k (si no queremos usar esta herramienta que nos customiza a nuestro gusto. Podemos usar algunos temas que están ya creados como el jonathan que es el que más me gusta: https://github.com/ohmyzsh/ohmyzsh/wiki/Themes )

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

y lo siguiente que vamos hacer es copiar el siguiente configuración en la ZSHRC

nano ~/.zshrc

"export ZSH='$HOME/.oh-my-zsh'"

#ZSH_THEME="jonathan" 
ZSH_THEME="powerlevel10k/powerlevel10k"


ENABLE_CORRECTION="true"


plugins=(wp-cli git colored-man-pages colorize command-not-found compleat history-substring-search zsh-autosuggestions zsh-syntax-highlighting sudo fzf)

source $ZSH/oh-my-zsh.sh

alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias pip3-upgrade="pip3 freeze --user | cut -d'=' -f1 | xargs -n1 pip3 install -U"
alias cat='bat --paging=never --theme=Coldark-Dark'
alias ll='lsd -lh --group-dirs=first'
alias la='lsd -a --group-dirs=first'
alias l='lsd --group-dirs=first'
alias lla='lsd -lha --group-dirs=first'
alias ls='lsd --group-dirs=first'
alias lst='lsd --tree --group-dirs=first'
alias ifoto='feh'
alias lzd='docker run --rm -it --name LazyDock -v /var/run/docker.sock:/var/run/docker.sock -v lazydocker:/.config/jesseduffield/lazydocker lazyteam/lazydocker'


# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

#Funciones

function taillogs(){
        sudo tail -f $1 | bat --paging=never -l log
}

function  sys-update(){
        sudo apt-get update && sudo apt-get dist-upgrade && sudo apt-get autoclean
}

si reiniciamos el terminal nos saldrá con la configuración actual .

Si queremos que el root tenga el mismo aspecto tendremos que repetir los pasos de instalación de ho-my-zsh, instalar las dos librerías , el Powerlevel10K y el archivo ZSHRC.

Solo me queda instalar un gestor de ventanas tipo tmux , en este caso voy a usar byobu que es muy sencillito. y que me permite mantener las tty activas en donde las deje para poder seguir trabajando: https://www.byobu.org/

en este caso la instalación es más sencilla:

sudo apt-get install byobu

y lo activamos con :

byobu-enable

ya solo tenemos reiniciar la terminal y arrancaremos con el byobu .

Nota :

Si queremos controlar el theme del BATCAT podemos usar esto:

bat --list-themes | fzf --preview="bat --theme={} --color=always /etc/passwd"

Deja un comentario