Skip to content

Instantly share code, notes, and snippets.

View herder's full-sized avatar

Niklas Herder herder

View GitHub Profile

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]}
https://github.com/robbyrussell/oh-my-zsh/issues/5327
A Debugging Technique
I didn't read every post here, but I'm gonna post a technique for debugging slow startup just in case no one else has posted a good one yet.
If you install the moreutils package, you'll have a timestamp command called ts. You can use it to print sub second resolution timestamps of all of the debug output from zsh that tell you how long since the last line of output. Then you can search that file for timestamps that are "long". Here's the command:
zsh -xv 2>&1 | ts -i "%.s" > zsh_startup.log
Just hit 'ctrl-d' when the prompt pops up to exit the debug shell, and you can then read 'zsh_startup.log' with whatever you want. It'll be a long file, so find a good way to search it with regex. Keep in mind that zsh debug prints a line before running it, so the timestamps really tell you how long it took for the previous line to run, not the line the timestamp is currently on.
@graemerocher
graemerocher / migrate-jira-to-github-issues.groovy
Last active November 19, 2024 15:23
JIRA to Github Issues Migration Script
@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='1.1.0')
@Grab(group='joda-time', module='joda-time', version='2.7')
import wslite.rest.*
import org.joda.time.*
import org.joda.time.format.*
import groovy.xml.*
import groovy.json.*
import static java.lang.System.*
import groovy.transform.*
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))