From a974024add77ab70915ca66a18398ae60fe32196 Mon Sep 17 00:00:00 2001 From: juancwu <46619361+juancwu@users.noreply.github.com> Date: Sun, 1 Oct 2023 14:41:17 -0400 Subject: [PATCH] move from fish to zsh in mac. Ditching fish because its a PAIN IN THE ASS TO WORK WITH --- .config/fish/config-darwin.fish | 4 ++ .config/fish/config.fish | 25 ++------ .config/nvim/lua/plugins/lsp-zero.lua | 4 +- .config/zsh/aliases.zsh | 2 + .config/zsh/functions.zsh | 87 +++++++++++++++++++++++++++ .config/zsh/zshrc.zsh | 25 ++++++++ 6 files changed, 125 insertions(+), 22 deletions(-) create mode 100644 .config/zsh/aliases.zsh create mode 100644 .config/zsh/functions.zsh create mode 100644 .config/zsh/zshrc.zsh diff --git a/.config/fish/config-darwin.fish b/.config/fish/config-darwin.fish index fe215a7..67c62cd 100644 --- a/.config/fish/config-darwin.fish +++ b/.config/fish/config-darwin.fish @@ -1,3 +1,7 @@ # Config file for macOS eval "$(/opt/homebrew/bin/brew shellenv)" +# +# set -x NVM_DIR "$HOME/.nvm" +# +# nvm use >/dev/null diff --git a/.config/fish/config.fish b/.config/fish/config.fish index a0396da..9f269f0 100644 --- a/.config/fish/config.fish +++ b/.config/fish/config.fish @@ -49,21 +49,6 @@ if type -q tmux alias tmks "tmux kill-session" end -if type -q nvm - nvm use >/dev/null -end - -if type -q lazygit - alias lg "lazygit" -end - -function fish_greeting - echo "Welcome Back Juan!" - if type -q nvm - echo "Current Node:$(nvm current)" - end -end - # allow local config overwrite set LOCAL_CONFIG (dirname (status --current-file))/config-local.fish if test -f $LOCAL_CONFIG @@ -71,10 +56,8 @@ if test -f $LOCAL_CONFIG end # pnpm -set -gx PNPM_HOME "/home/jc/.local/share/pnpm" -set -gx PATH "$PNPM_HOME" $PATH +set -gx PNPM_HOME "/Users/jc/Library/pnpm" +if not string match -q -- $PNPM_HOME $PATH + set -gx PATH "$PNPM_HOME" $PATH +end # pnpm end - -# bun -set --export BUN_INSTALL "$HOME/.bun" -set --export PATH $BUN_INSTALL/bin $PATH diff --git a/.config/nvim/lua/plugins/lsp-zero.lua b/.config/nvim/lua/plugins/lsp-zero.lua index 474b04b..34499c1 100644 --- a/.config/nvim/lua/plugins/lsp-zero.lua +++ b/.config/nvim/lua/plugins/lsp-zero.lua @@ -4,7 +4,8 @@ return { dependencies = { -- LSP Support { 'neovim/nvim-lspconfig' }, -- Required - { -- Optional + { + -- Optional 'williamboman/mason.nvim', build = function() pcall(vim.cmd, 'MasonUpdate') @@ -81,6 +82,7 @@ return { if status then lspconfig.tsserver.setup({}) lspconfig.tailwindcss.setup({}) + lspconfig.zls.setup({}) end lspzero.setup() diff --git a/.config/zsh/aliases.zsh b/.config/zsh/aliases.zsh new file mode 100644 index 0000000..179ae0b --- /dev/null +++ b/.config/zsh/aliases.zsh @@ -0,0 +1,2 @@ +alias ll='ls -l' +alias lla='ls -la' diff --git a/.config/zsh/functions.zsh b/.config/zsh/functions.zsh new file mode 100644 index 0000000..6683cea --- /dev/null +++ b/.config/zsh/functions.zsh @@ -0,0 +1,87 @@ +# list directory and cd into it +sd() { + local path=${1:-.} + local result=$(ls -d ${path}/*/ 2> /dev/null | fzf) + if [[ -n "${result}" ]]; then + cd "${result}" + else + echo "No directories found or no selection made." + fi +} + +# list files and opens it in neovim +sf() { + local path=${2:-.} + if [[ $1 == "-h" ]]; then + local result=$(find ${path} -type f -name '.*' 2> /dev/null | fzf) + else + local result=$(find ${path} -type f 2> /dev/null | fzf) + fi + if [[ -n "${result}" ]]; then + nvim "${result}" + else + echo "No files found or no selecteion made." + fi +} + +# fuzzy cd into specific folders +fcd() { + local selected_dir=$({ + echo "$HOME/.config" + find "$HOME/ghq" -mindepth 2 -maxdepth 2 -type d + ls -d -1 "$HOME/"/*/ | grep -v \.git + ls -d -1 */ | perl -pe "s#^#$PWD/#" | grep -v \.git + } | fzf) + + if [ -n "$selected_dir" ]; then + cd "$selected_dir" + if [[ -f .nvmrc ]]; then + NVMRC_VERSION=$(cat .nvmrc) + CURRENT_VERSION=$(nvm current) + if [ "$NVMRC_VERSIOn" != "$CURRENT_VERSION" ]; then + nvm use + fi + fi + else + echo "No selection made." + fi +} + +# clone repository +# setopt EXTENDED_GLOB +gc() { + local url=$1 + local ghq_dir="$HOME/ghq" + + # extract project name + if [[ $url =~ git@github\.com:([^/]+)/([^/]+)\.git ]]; then + local project_name="${match[1]}" + local repository_name="${match[2]}" + elif [[ $url =~ https://github\.com/([^/]+)/([^/]+)\.git ]]; then + local project_name="${match[1]}" + local repository_name="${match[2]}" + else + echo "Invalid URL format" + return 1 + fi + + # check if directory for project exists or not + local project_dir="${ghq_dir}/${project_name}/${repository_name}" + echo $project_dir + if [[ ! -d $project_dir ]]; then + mkdir -p $project_dir + fi + + git clone $url $project_dir +} + +# get branch if available +parse_git_branch() { + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' +} + +# delete local branches that don't exists in remote repository +git-prune() { + git fetch --prune + git branch -vv | grep '\[origin/.*: gone\]' | awk '{print $1}' | xargs git branch -d +} diff --git a/.config/zsh/zshrc.zsh b/.config/zsh/zshrc.zsh new file mode 100644 index 0000000..bfe576f --- /dev/null +++ b/.config/zsh/zshrc.zsh @@ -0,0 +1,25 @@ +ZSH_CONFIG="$(dirname ${(%):-%x})" + +# Functions! +source "$ZSH_CONFIG/dotfiles/.config/zsh/functions.zsh" + +# Aliases +source "$ZSH_CONFIG/dotfiles/.config/zsh/aliases.zsh" + +export PATH=/Users/jc/Library/Python/3.8/bin:$PATH +export BREW_PYTHON=/opt/homebrew/bin/python3 + +# NVM !! +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm +[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion + +# bun completions +[ -s "/Users/jc/.bun/_bun" ] && source "/Users/jc/.bun/_bun" + +# bun +export BUN_INSTALL="$HOME/.bun" +export PATH="$BUN_INSTALL/bin:$PATH" + +# PRETTIERD +export PRETTIERD_DEFAULT_CONFIG="$HOME/.prettierrc.json"