Skip to content

Instantly share code, notes, and snippets.

View mattmc3's full-sized avatar
🐍
Python!

mattmc3 mattmc3

🐍
Python!
View GitHub Profile
@mattmc3
mattmc3 / .zshrc
Last active September 13, 2021 11:34
ZSH - .zshrc that emulates fish's conf.d and functions dirs
# A minimal .zshrc that uses a .zshrc.d for its content
# load zprof first if we need to profile
[[ ${ZSH_PROFILE_RC:-0} -eq 0 ]] || zmodload zsh/zprof
# helpful profiling aliases
alias zprofrc="ZSH_PROFILE_RC=1 zsh"
alias zbench='for i in $(seq 1 10); do; /usr/bin/time zsh -i -c exit; done'
# source all scripts in a config dir
@mattmc3
mattmc3 / split.zsh.md
Last active March 31, 2024 15:34
ZSH - split string into array

Example splitting string on slash character in ZSH.

$ str=part1/part2/part3
$ parts=(${(@s:/:)str})
$ echo $parts
part1 part2 part3
$ echo ${#parts[@]}
3
@mattmc3
mattmc3 / brew_export.sh
Last active May 14, 2022 17:12
Brew - better Brewfile creation (without the file)
brew_export() {
# brew bundle is a pain... it dumps to a forced Brewfile, and is not
# consistently sorted, making version controling your Brewfile in a dotfile
# repo tricky. #FixedIt
# makes a Brewfile
brew bundle dump --force
# add custom sort column
awkcmd='
@mattmc3
mattmc3 / tampermonkey-stackoverflow.js
Last active November 18, 2019 15:56
Tampermonkey - my scripts
// ==UserScript==
// @name stackoverflow tampering
// @namespace http://tampermonkey.net/
// @version 0.1
// @description StackOverflow - hide #hot-network-questions and deleted stuff.
// @author mattmc3
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// @match https://*.stackoverflow.com
// @match https://*.stackexchange.com
@mattmc3
mattmc3 / example.zsh
Created November 4, 2019 20:07
ZSH - array contains value
# http://zsh.sourceforge.net/Doc/Release/Parameters.html#Subscript-Flags
# https://unix.stackexchange.com/questions/411304/how-do-i-check-whether-a-zsh-array-contains-a-given-value/411306
array=(foo bar baz foo)
# 'I' is the subscript flag for index
pattern=f*
if (($array[(I)$pattern])); then
echo array contains at least one value that matches the pattern
fi
@mattmc3
mattmc3 / .zshrc_part.zsh
Created October 22, 2019 21:56
ZSH - manually manage plugins
# assumes github and slash separated plugin names
github_plugins=(
zsh-users/zsh-autosuggestions
zsh-users/zsh-completions
zsh-users/zsh-history-substring-search
rupa/z
# theme
miekg/lean
# must be last
zdharma/fast-syntax-highlighting
@mattmc3
mattmc3 / 01 - test_834.edi
Last active December 24, 2023 00:55
AWK - convert HIPAA 5010 X12 834 Benefit Enrollment to TSV
ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>
GS*PO*4405197800*999999999*20101127*1719*1421*X*004010VICS
ST*834*0179
BGN*00*1*20050315*110650****4
REF*38*SAMPLE_POLICY_NUMBER
DTP*303*D8*20080321
N1*P5*COMPAN_NAME*FI*000000000
INS*Y*18*030*20*A
REF*0F*SUBSCRIBER_NUMBER
NM1*IL*1*JOHN DOE*R***34*1*0000000
@mattmc3
mattmc3 / zsh-strings.md
Last active April 1, 2024 22:44
Zsh - string utilities

zsh strings

Fish has a utility for [string maniplulation][string].

This is how you can do the same things with Zsh builtins.

References:

  • [Zsh regex][3]
  • [String modifiers][1]
  • [String expansion][2]
@mattmc3
mattmc3 / README.md
Last active January 2, 2024 00:50
zsh: zstyle examples

zstyle booleans

Setup foo,bar,baz boolean vars

zstyle ':example:foo' doit yes
zstyle ':example:bar' doit no
# leave baz unset
@mattmc3
mattmc3 / 1-setopts.zsh
Last active January 2, 2024 15:47
ZSH - options by framework
## ZSH Options
# http://zsh.sourceforge.net/Doc/Release/Options.html
# Changing Directories
# http://zsh.sourceforge.net/Doc/Release/Options.html#Changing-Directories
setopt auto_cd # if a command isn't valid, but is a directory, cd to that dir
setopt auto_pushd # make cd push the old directory onto the directory stack
setopt pushd_ignore_dups # don’t push multiple copies of the same directory onto the directory stack
setopt pushd_minus # exchanges the meanings of ‘+’ and ‘-’ when specifying a directory in the stack