Logo

dev-resources.site

for different kinds of informations.

Some Config Ideas for your ZSH

Published at
8/24/2024
Categories
bash
zsh
productivity
tooling
Author
gokayburuc
Categories
4 categories in total
bash
open
zsh
open
productivity
open
tooling
open
Author
10 person written this
gokayburuc
open
Some Config Ideas for your ZSH

Introduction

ZSH shell users often aim to personalize their systems with short edits on the .zshrc file, to provide faster access and to do multiple tasks with a single and short command. Below I am sharing a few ideas from my own .zshrc configurations with you.

All you need to do is save the boilerplate codes I shared to your .zshrc file and activate them with the source ~/.zshrc command.

FFMPEG Webp file Converter

Requires ffmpeg

This function converts your .webp files into .png files.

## INFO: FFMPEG WEBP CONVERTER
convert_webp() {
  for i in *
  do

  if [[ "${i##*.}" == "webp" ]]; then

      echo "WEBP FILE => $i"

      # show filename
      filename="${i%.*}"

      # show Extension
      extension="${i##*.}"

      ## webp converter
      ffmpeg -i "$filename" "$filename.png"

    fi
  done
  }

Enter fullscreen mode Exit fullscreen mode

Usage:

$convert_webp

Enter fullscreen mode Exit fullscreen mode

Creating New Obsidian Note From Terminal

Requires pre-defined obsidian vault

To create new obsidian markdown note from your terminal you can use this function:

vn(){
  ov  # open vault
  local filename="$1"
  if [[ -z "$filename" ]]; then
    echo "Usage: vn <filename>"
    return 1

  fi
  #use your own path <filepath>
  nvim "00_inbox/${filename}.md" # enter file-name and directly start writing
}
Enter fullscreen mode Exit fullscreen mode

This function changes directory into your vault and creates a new markdown note with the given filename.

Usage:

$vn my-first-article

Enter fullscreen mode Exit fullscreen mode

Zoxide

Requires zoxide

This is the zsh config for the zoxide

# zoxide
eval "$(zoxide init zsh)"
Enter fullscreen mode Exit fullscreen mode

Now you can use fast folder navigations only putting the prefix z and you can discover the world of zoxide.

Usage:

# cd into $HOME/Documents/vaults/  directly
z Doc/vau
Enter fullscreen mode Exit fullscreen mode

Fast Folder Access

Sometimes i need shortcuts to access my folders directly. So i declared them all.

## foldershortcuts
alias ob="cd /$HOME/Documents/workspace/static_website/hugo/gokayburuc_weblog/"
alias oc="cd /$HOME/.config/nvim/"
alias ok="cd /$HOME/.config/kitty/"
alias od="cd /$HOME/Downloads/"
alias om="cd /$HOME/Documents/workspace/static_website/mdbook/golang_cookbook/"
alias ov="cd /$HOME/Documents/vaults/secondbrain/"
alias ow="cd /$HOME/Documents/workspace"
Enter fullscreen mode Exit fullscreen mode

Those are shortcut to my directories. Frequiently used paths are now accessible with only 2 letters from commandline.

Usage:

# goes into directly into the $HOME/Documents/vaults/secondbrain/
$ov
Enter fullscreen mode Exit fullscreen mode

Tmux Shortcuts

# tmux shortcuts
alias tconf="nvim ~/.tmux.conf"
alias t="tmux"
alias tn="tmux new"
alias ta="tmux attach-session"
alias trw="tmux rename-window"
alias trs="tmux rename-session"

Enter fullscreen mode Exit fullscreen mode

Usage:

# creates new section with name my-session
$tn my-session

# attaches session 0
$ta -t0

# renames window as conf
$trw conf

# renames session as home
$trs home


Enter fullscreen mode Exit fullscreen mode

Listen Music From Your Terminal

Requires mpv , fzf , rg

Listening music via mpv from your terminal:

# listen music
alias lmusic='cd ~/Music/ && rg --files --glob "*.mp3" | fzf --multi --reverse --prompt="Song: " | xargs mpv --audio-display=no'
Enter fullscreen mode Exit fullscreen mode

Usage:

  1. Search favorite songs and add to your playlist using TAB

Adding New Paths to a List

This code block controls every path and duplicates and export every path in list to the $PATHENV directly.

# Define an array of directories to add to PATH
path=(
    $path                           # Keep existing PATH entries
    $HOME/bin
    $HOME/.local/bin
    $HOME/dotnet
    $SCRIPTS
    $HOME/.krew/bin
    $HOME/.rd/bin                   # Rancher Desktop
    # $HOME/*/bin(N)                # Add all bin directories under HOME
    # /usr/local/*/bin(N)           # Add all bin directories under /usr/local
)

# Remove duplicate entries and non-existent directories
typeset -U path
path=($^path(N-/))

# Export the updated PATH
export PATH

Enter fullscreen mode Exit fullscreen mode

Usage:

This code block add new paths and checks duplicates automatically, finally adds to your PATH. Just add your new path into the brackets with given format.

Extended Glob Operations

Β·# Enable Zsh's extended globbing and null_glob options
setopt extended_glob null_glob
Enter fullscreen mode Exit fullscreen mode

Enables extended glob in your filesystem for your ZSH.

extended_glob

  • In zsh: The extended_glob option allows for more advanced pattern matching in filenames. It enables extended globbing features such as ** for recursive directory matching, ^ for negating patterns, and more.
  • In bash: The equivalent feature is controlled by the shopt -s extglob command. When enabled, it allows extended pattern matching.

null_glob

  • In zsh: The null_glob option makes filename patterns that do not match any files expand to an empty list rather than remaining as the original pattern. This can be useful to avoid errors when patterns don’t match any files.
  • In bash: The equivalent functionality can be achieved by setting the nullglob option using shopt -s nullglob. When enabled, if a pattern does not match any files, it expands to nothing instead of remaining as the pattern.

Conclusion

This article is written for the .zshrc capability and is meant to show you what you can do by modifying your .zshrc in the terminal.

zsh Article's
30 articles in total
Favicon
Understanding Linux Shells: Interactive, Non-Interactive, and RC Files
Favicon
Enhance Your macOS Terminal with Oh My Zsh, Autosuggestions, and Powerlevel10k
Favicon
Oh My Zsh: A Simple Guide for Developers
Favicon
Display Dir Structure in Tree Format.
Favicon
A Guide to Setting Up Zsh: Improving Your Terminal Experience
Favicon
OMZ: Some Plugins that I forget about
Favicon
Managing dotfiles using GNU Stow on macOS
Favicon
Copy paste bash command but dont understand what it does?
Favicon
How do I show the git branch with colours in Bash prompt?
Favicon
Demystifying Bash and Zsh on Mac
Favicon
How to make your terminal looks Splendid
Favicon
Adding Zsh Completion for `gh copilot`
Favicon
Docker aliases with zsh using Ohmyzsh
Favicon
Improve your PowerShell experience
Favicon
Colorful terminals with Oh My Posh and Windows Terminal
Favicon
Some Config Ideas for your ZSH
Favicon
Ma configuration post-installation d'Arch Linux
Favicon
πŸš€ Simplify Your Linux Process Killing with a Fuzzy Process Killer πŸš€
Favicon
How to Remove Duplicate Paths in ZSH on MacOS
Favicon
zsh: permission denied: ./gradlew
Favicon
How to install oh-my-zsh and zsh-autosuggestions for macbook
Favicon
Add Visual Studio Code to your OSX zsh PATH
Favicon
Simple Directory Watcher to Restart Dev Server
Favicon
πŸš€ Um Guia PrΓ‘tico para Configurar Zsh, Oh My Zsh, asdf e Spaceship Prompt com Zinit para Seu Ambiente de Desenvolvimento
Favicon
πŸš€ A hands-on guide to setting up zsh, oh my zsh, asdf, and spaceship prompt with zinit for your development environment
Favicon
My zsh config
Favicon
Finding Terminal Utopia
Favicon
How to stop Storybook opening a new webpage on start (automatically with zsh)
Favicon
zoxide - A faster alternative to boring cd command
Favicon
A quick bash/zsh tip

Featured ones: