Last active
January 5, 2024 09:06
-
-
Save LukasBombach/00662c40faaaa0d2cc46ed5f759549a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# My oh my zsh aliases and functions | |
# Configure oh my zsh | |
alias zshrc="code ~/.zshrc" | |
alias pkg="code ./package.json" | |
alias dev="run dev" | |
alias build="run build" | |
alias start="run start" | |
alias grstf="git checkout upstream/main --" | |
# Clone a repo into ~/Projects and open code | |
function np() { | |
if ! test -d "$HOME/Projects/$(basename "$1" .git)" ; then | |
git clone "$1" "$HOME/Projects/$(basename "$1" .git)" | |
fi | |
code "$HOME/Projects/$(basename "$1" .git)" | |
} | |
# Kill processes at a given port | |
function killport() { | |
lsof -i TCP:$1 | grep LISTEN | awk '{print $2}' | xargs kill -9 | |
echo "Port" $1 "found and killed." | |
} | |
# Run a command either by yarn or pnpm depending on the package manager in use | |
# I am using yarn as a default because I like it more than npm | |
function run() { | |
local command="${1:-install}" | |
if [ -f "bun.lockb" ]; then | |
echo "\n\033[92m➜\033[0m bun $command\n" | |
bun "$command" | |
elif [ -f "pnpm-lock.yaml" ]; then | |
echo "\n\033[92m➜\033[0m pnpm $command\n" | |
pnpm "$command" | |
elif [ -f "yarn.lock" ]; then | |
echo "\n\033[92m➜\033[0m yarn $command\n" | |
yarn "$command" | |
elif [ -f "package-lock.json" ]; then | |
echo "\n\033[92m➜\033[0m npm run $command\n" | |
npm run "$command" | |
else | |
echo "No lock file found" | |
fi | |
} | |
# Clears all caches on the system | |
function clear_all_developer_caches() { | |
echo "rm -rf ~/.cocoapods/" | |
rm -rf ~/.cocoapods/ | |
echo "pod cache clean --all" | |
pod cache clean --all | |
echo "yarn cache clean" | |
yarn cache clean | |
echo "All caches cleared." | |
} | |
function clear_node_and_next_etc() { | |
echo "find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +" | |
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' + | |
echo "find . -name '.next' -type d -prune -exec rm -rf '{}' +" | |
find . -name '.next' -type d -prune -exec rm -rf '{}' + | |
echo "find . -name '.expo' -type d -prune -exec rm -rf '{}' +" | |
find . -name '.expo' -type d -prune -exec rm -rf '{}' + | |
echo "find . -name '.contentlayer' -type d -prune -exec rm -rf '{}' +" | |
find . -name '.contentlayer' -type d -prune -exec rm -rf '{}' + | |
echo "Cleared all those things" | |
} | |
# Merge main from the upstream to the current branch and push to origin | |
function gmu() { | |
echo "" | |
echo "> git pull origin $(current_branch)" | |
git pull origin $(current_branch) | |
echo "" | |
echo "> git fetch upstream" | |
git fetch upstream | |
echo "" | |
echo "> git merge upstream/main --no-edit" | |
git merge upstream/main --no-edit | |
echo "" | |
echo "> git push origin $(current_branch)" | |
git push origin $(current_branch) | |
echo "" | |
} | |
# nvm with automatic node version switch based on the .nvmrc of a directory | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm | |
autoload -U add-zsh-hook | |
load-nvmrc() { | |
local nvmrc_path="$(nvm_find_nvmrc)" | |
if [ -n "$nvmrc_path" ]; then | |
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") | |
if [ "$nvmrc_node_version" = "N/A" ]; then | |
nvm install | |
elif [ "$nvmrc_node_version" != "$(nvm version)" ]; then | |
nvm use | |
fi | |
elif [ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ] && [ "$(nvm version)" != "$(nvm version default)" ]; then | |
echo "Reverting to nvm default version" | |
nvm use default | |
fi | |
} | |
add-zsh-hook chpwd load-nvmrc | |
load-nvmrc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment