Files
dev_prod/10x_alias.sh
2025-08-29 16:18:06 +05:30

72 lines
1.9 KiB
Bash

#!/bin/sh
# Templates
[ ! -f "$GITIGNORE_TEMPLATE" ] || alias cp_gi='cp ${GITIGNORE_TEMPLATE} .'
[ ! -f "$PRETTIER_TEMPLATE" ] || alias cp_prc='cp ${PRETTIER_TEMPLATE} .'
[ ! -f "$PRETTIER_IGNORE_TEMPLATE" ] || alias cp_prigr='cp ${PRETTIER_IGNORE_TEMPLATE} .'
command -v tldr >/dev/null && alias tldr="tldr --platform=linux"
command -v tldr >/dev/null && alias h="tldr"
command -v fzf >/dev/null && alias path="printenv | grep ^PATH= | sed 's/^PATH=//' | tr ':' '\n' | fzf"
command -v podman >/dev/null && alias docker=podman
alias cd_root='cd $(git rev-parse --show-toplevel 2>/dev/null || echo ".")'
alias cd_git_root=cd_root
git_push_all_changes() {
if [ -z "$1" ] || [ "$1" = " " ]; then
echo "Please provide a commit message."
return 126
fi
git add . && git commit -am "${1}" && git push
}
cp_gitprecommit() {
if [ ! -f "$GIT_PRECOMMIT_TEMPLATE" ]; then
echo "Git Pre-commit template does not exist"
return 1
fi
hooks_dir="$(pwd)/.git/hooks"
if [ ! -d "$hooks_dir" ]; then
echo "Git repository not found under $(pwd)"
return 2
fi
if [ -f "$hooks_dir/$(basename "$GIT_PRECOMMIT_TEMPLATE")" ]; then
echo "pre-commit hook already exist. Skipping..."
return 0
fi
cp "$GIT_PRECOMMIT_TEMPLATE" "$hooks_dir" && printf "Pre-commit hook template copied to %s\n" "$hooks_dir"
}
alias ls='ls --color=auto --hyperlink'
alias ll='ls -alhF'
alias la='ls -Ah'
alias lsa="ls -lAFhZ"
alias printpath="echo $PATH | tr : '\n'"
port_who() {
if [ -z "$1" ] || [ "$1" = " " ]; then
echo "Please provide port number"
return 127
fi
lsof -i :"$1"
is_listening=$(lsof -i :"$1" | wc -l)
if [ "$is_listening" = 0 ]; then
return
fi
printf "\nKill above processes? : (y/n) "
read -r to_kill
if [ "$to_kill" = "y" ]; then
lsof -ti :"$1" | xargs kill -9 && echo "Successfully killed the processes listening on port $1"
fi
}