Skip to content

Instantly share code, notes, and snippets.

ZSH CheatSheet

This is a cheat sheet for how to perform various actions to ZSH, which can be tricky to find on the web as the syntax is not intuitive and it is generally not very well-documented.

Strings

Description Syntax
Get the length of a string ${#VARNAME}
Get a single character ${VARNAME[index]}
@blizzrdof77
blizzrdof77 / new_env_var.sh
Created September 15, 2020 23:03
Create new environment variable & print assignment statement to your shell's '.rc' file
# -----------------------------------------
# Create new environment variable & print assignment statement to your shell's '.rc' file
#
# @1 = variable new
# @2 = variable definition
# @requires: '~/.zshrc' or '~/.bashrc'
# -----------------------------------------
function new_env_var {
local detected_shell="$(ps -o comm= -p $$)"
local rcfile=$(echo "${HOME}/.${detected_shell//-/}rc")
@Ariel-Rodriguez
Ariel-Rodriguez / semver.sh
Last active June 9, 2023 22:00
semver compare tool in bash
#!/bin/bash
# THIS IS AN OBSOLETE SCRIPT WITH BUGS. FOR UPDATED VERSIONS PLEASE CHECK https://github.com/Ariel-Rodriguez/sh-semversion-2
###
# semantic version comparition using semver specification http://semver.org/
# This bash script compares pre-releases alphabetically as well
#
# returns 1 when A greater than B
# returns 0 when A equals B