move functions and aliases to one file (zsh)
This commit is contained in:
parent
df2b76db5b
commit
cf4b8eea14
4 changed files with 171 additions and 114 deletions
171
.config/zsh/.zshrc
Normal file
171
.config/zsh/.zshrc
Normal file
|
|
@ -0,0 +1,171 @@
|
||||||
|
# set a fancy prompt (non-color, unless we know we "want" color)
|
||||||
|
case "$TERM" in
|
||||||
|
xterm-color|*-256color) color_prompt=yes;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# enable color support for ls and grep (even tho i don't use grep ???)
|
||||||
|
alias ls='ls --color=auto'
|
||||||
|
alias grep='grep --color=auto'
|
||||||
|
|
||||||
|
# -------------- Aliases
|
||||||
|
alias gs="git status"
|
||||||
|
|
||||||
|
# ll alias breakdown
|
||||||
|
# -a includes hidden files
|
||||||
|
# -l displays the listing in long format, showing file attributes such as permissions
|
||||||
|
# -F appends a character to each entry in the listing to indicate the file type (e.g '/' for directories and '*' for executables)
|
||||||
|
alias ll="ls -alF"
|
||||||
|
|
||||||
|
# la alias breakdown
|
||||||
|
# -A list all entries without ./ and ../
|
||||||
|
alias la="ls -A"
|
||||||
|
|
||||||
|
# l alias breakdown
|
||||||
|
# -C list entries by columns
|
||||||
|
# -F appends a character to each entry in the listing to indicate the file type (e.g '/' for directories and '*' for executables)
|
||||||
|
alias l="ls -CF"
|
||||||
|
|
||||||
|
# Nice line headers for logs
|
||||||
|
ERROR=$'\033[39;41mERROR:\033[0m'
|
||||||
|
SUCCESS=$'\033[39;42mSUCCESS:\033[0m'
|
||||||
|
WARNING=$'\033[39;43mWARNING:\033[0m'
|
||||||
|
INFO=$'\033[39;44mINFO:\033[0m'
|
||||||
|
|
||||||
|
# ------------ Functions!
|
||||||
|
# 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
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load colors if possible
|
||||||
|
autoload -U colors && colors
|
||||||
|
|
||||||
|
# Set prompt
|
||||||
|
if [[ "$color_prompt" == "yes" ]]; then
|
||||||
|
PS1="%{$fg_bold[green]%}%n@%m%{$reset_color%}:%{$fg_bold[blue]%}%~%{$fg_bold[red]%}$(parse-git-branch)%{$reset_color%} $ "
|
||||||
|
else
|
||||||
|
PS1="%n@%m:%~$(parse-git-branch)$ "
|
||||||
|
fi
|
||||||
|
unset color_prompt
|
||||||
|
|
||||||
|
type -p curl >/dev/null || echo -e "$WARNING curl is not installed"
|
||||||
|
|
||||||
|
command -v nvm > /dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "$WARNING nvm is not installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
command -v pnpm > /dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "$WARNING pnpm is not installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
command -v gh > /dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "$WARNING gh cli is not installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
command -v nvim > /dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "$ERROR neovim is not installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
command -v yarn > /dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "$WARNING yarn is not installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
command -v bun > /dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "$WARNING bun is not installed"
|
||||||
|
fi
|
||||||
|
|
||||||
|
command -v lazygit > /dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "$WARNING lazygit is not installed"
|
||||||
|
else
|
||||||
|
alias lg="lazygit"
|
||||||
|
fi
|
||||||
|
|
@ -1,2 +0,0 @@
|
||||||
alias ll='ls -l'
|
|
||||||
alias lla='ls -la'
|
|
||||||
|
|
@ -1,87 +0,0 @@
|
||||||
# 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
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
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"
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue