|
| 1 | +# Random bag of tricks |
| 2 | + |
| 3 | +## Teach yourself quickly what package manager to use |
| 4 | + |
| 5 | +```zsh |
| 6 | +NPM_PATH=$(which npm) |
| 7 | +npm () { |
| 8 | + if [ -e PNPM-lock.yaml ] |
| 9 | + then |
| 10 | + echo "Please use PNPM with this project" |
| 11 | + elif [ -e yarn.lock ] |
| 12 | + then |
| 13 | + echo "Please use Yarn with this project" |
| 14 | + else |
| 15 | + $NPM_PATH "$@" |
| 16 | + fi |
| 17 | +} |
| 18 | + |
| 19 | +YARN_PATH=$(which yarn) |
| 20 | +yarn () { |
| 21 | + if [ -e PNPM-lock.yaml ] |
| 22 | + then |
| 23 | + echo "Please use PNPM with this project" |
| 24 | + elif [ -e package-lock.json ] |
| 25 | + then |
| 26 | + echo "Please use NPM with this project" |
| 27 | + else |
| 28 | + $YARN_PATH "$@" |
| 29 | + fi |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +## Git tricks |
| 34 | + |
| 35 | +### Aliases |
| 36 | + |
| 37 | +Aliases to easily update your main branch, e.g after PR was merged. |
| 38 | +It updates the branch in the background before switching to it, so that editor/tooling experience the least changes. |
| 39 | + |
| 40 | +- `upc`: update specified branch (defaults to `main`), and switch to it |
| 41 | +- `upd`: update specified branch (defaults to `main`) |
| 42 | + |
| 43 | +``` |
| 44 | +[alias] |
| 45 | + upc = "!git updonly \"${1:-main}\" && git checkout \"${1:-main}\" || git pull #" |
| 46 | + upd = "!git updonly \"${1:-main}\" || git pull #" |
| 47 | + updonly = "!git fetch `git gitremote \"$1\"` \"$1\":\"$1\" #" |
| 48 | + gittrack = "!git for-each-ref --format='%(upstream:short)' $(git rev-parse --symbolic-full-name \"$1\") #" |
| 49 | + gitremote = "!git gittrack \"$1\" | sed 's@/.*@@' #" |
| 50 | +``` |
| 51 | + |
| 52 | +### Other recommendations |
| 53 | + |
| 54 | +``` |
| 55 | +[pull] |
| 56 | + rebase = true |
| 57 | +[rebase] |
| 58 | + autoStash = true |
| 59 | +[init] |
| 60 | + defaultBranch = main |
| 61 | +``` |
| 62 | + |
| 63 | +## Znap - Oh My Posh and pnpm auto completion support |
| 64 | + |
| 65 | +Install oh-my-posh, install pnpm autocomple zsh, and use: |
| 66 | + |
| 67 | +```zsh |
| 68 | +#znap |
| 69 | +# Download Znap, if it's not there yet. |
| 70 | +[[ -f ~/Git/zsh-snap/znap.zsh ]] || |
| 71 | + git clone --depth 1 -- \ |
| 72 | + https://github.com/marlonrichert/zsh-snap.git ~/Git/zsh-snap |
| 73 | + |
| 74 | +source ~/Git/zsh-snap/znap.zsh # Start Znap |
| 75 | + |
| 76 | +# `znap prompt` makes your prompt visible in just 15-40ms! |
| 77 | +#znap prompt sindresorhus/pure |
| 78 | + |
| 79 | +# `znap source` automatically downloads and starts your plugins. |
| 80 | +znap source marlonrichert/zsh-autocomplete |
| 81 | +znap source zsh-users/zsh-autosuggestions |
| 82 | +znap source zsh-users/zsh-syntax-highlighting |
| 83 | + |
| 84 | +# `znap eval` caches and runs any kind of command output for you. |
| 85 | +znap eval iterm2 'curl -fsSL https://iterm2.com/shell_integration/zsh' |
| 86 | + |
| 87 | +# `znap function` lets you lazy-load features you don't always need. |
| 88 | +znap function _pyenv pyenv 'eval "$( pyenv init - --no-rehash )"' |
| 89 | +compctl -K _pyenv pyenv |
| 90 | + |
| 91 | +znap eval ohmyposh 'oh-my-posh --init --shell zsh --config ~/jandedobbeleer.omp.json' |
| 92 | +znap prompt |
| 93 | + |
| 94 | +source $XDG_CONFIG_HOME/tabtab/zsh/pnpm.zsh |
| 95 | +``` |
0 commit comments