modifyed gwip function
This commit is contained in:
parent
706f690a8e
commit
382312eb23
2 changed files with 97 additions and 65 deletions
|
@ -41,6 +41,14 @@ else
|
|||
alias hl="grep --passthrough"
|
||||
fi
|
||||
|
||||
ffile() {
|
||||
if [ -z $2 ]; then
|
||||
find -type f "${1:-./**}"
|
||||
else
|
||||
find -type f "'${1:-./**}'" -name "${2}"
|
||||
fi
|
||||
}
|
||||
|
||||
if command_exists dog; then
|
||||
alias dig="dog"
|
||||
fi
|
||||
|
@ -484,26 +492,64 @@ __git__() {
|
|||
|
||||
# Check if there are any changes on the remote branch
|
||||
if git diff --quiet "$branch" "origin/$branch"; then
|
||||
local commit_files
|
||||
local commit_files=()
|
||||
local commit_message
|
||||
|
||||
if [ -n "$2" ]; then
|
||||
commit_files="$1"
|
||||
commit_message="$2"
|
||||
else
|
||||
if [ -e "$1" ]; then
|
||||
commit_files="$1"
|
||||
commit_message="wip"
|
||||
else
|
||||
commit_files="."
|
||||
commit_message="${1:-wip}"
|
||||
fi
|
||||
fi
|
||||
case "$1" in
|
||||
'.')
|
||||
commit_files=.
|
||||
commit_message="wip"
|
||||
|
||||
echo "${CYAN}No changes on the remote branch. Adding changes and pushing with ${RED}${BOLD}'$commit_message'${NC}${CYAN} commit.${NC}"
|
||||
git add "$commit_files"
|
||||
git commit -m "$commit_message"
|
||||
git push
|
||||
echo "${CYAN}No changes on the remote branch. Adding changes and pushing with ${RED}${BOLD}'$commit_message'${NC}${CYAN} commit.${NC}"
|
||||
# echo "${GREEN}Committed files: ${BOLD}${commit_files[*]}${NC}"
|
||||
|
||||
git add "$commit_files"
|
||||
git commit -m "$commit_message"
|
||||
git push
|
||||
;;
|
||||
*)
|
||||
|
||||
if [[ -n "$1" ]]; then
|
||||
for f in "$@"; do
|
||||
if [ -e "$f" ]; then
|
||||
commit_files+=("$f")
|
||||
# shift
|
||||
else
|
||||
commit_message+="${f}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
echo "${BOLD}${YELLOW}You have to provide the command like..:"
|
||||
echo "${GREEN}'gwip <list of files> <commit message>' or like 'gwip .'${NC}"
|
||||
return
|
||||
fi
|
||||
|
||||
[[ -z "$commit_files" ]] && commit_files=.
|
||||
|
||||
echo "${CYAN}No changes on the remote branch. Adding changes and pushing with ${RED}${BOLD}'$commit_message'${NC}${CYAN} commit.${NC}"
|
||||
echo "${GREEN}Committed files: ${BOLD}${commit_files[*]}${NC}"
|
||||
# for f in "${commit_files[@]}"; do
|
||||
# echo git add "$f"
|
||||
# done
|
||||
git add "${commit_files[*]}"
|
||||
git commit -m "${commit_message:-wip}"
|
||||
git push
|
||||
;;
|
||||
esac
|
||||
|
||||
# if [ -n "$2" ]; then
|
||||
# commit_files="$1"
|
||||
# commit_message="$2"
|
||||
# else
|
||||
# if [ -e "$1" ]; then
|
||||
# commit_files="$1"
|
||||
# commit_message="wip"
|
||||
# else
|
||||
# commit_files="."
|
||||
# commit_message="${1:-wip}"
|
||||
# fi
|
||||
# fi
|
||||
else
|
||||
echo "${RED}${BOLD}There are changes on the remote branch. Please pull the latest changes first.${NC}"
|
||||
fi
|
||||
|
@ -551,29 +597,6 @@ else
|
|||
echo_missing "tmux"
|
||||
fi
|
||||
|
||||
# Zellij session manager
|
||||
# if command_exists zellij; then
|
||||
# za() {
|
||||
# # local zsession='zellij list-sessions | tail -1 | grep -q EXITED'
|
||||
# if ! zellij list-sessions >/dev/null 2>&1; then
|
||||
# echo "-- Zellij session active! | Connecting to existing session --"
|
||||
# sleep 0.3
|
||||
# zellij attach
|
||||
# elif ! zellij list-sessions | tail -1 | grep -q EXITED; then
|
||||
# echo "-- Zellij session active! | Connecting to existing session --"
|
||||
# sleep 0.3
|
||||
# zellij attach
|
||||
# else
|
||||
# echo "-- No Zellij session active! | Creating one --"
|
||||
# sleep 0.3
|
||||
# zellij
|
||||
# fi
|
||||
# }
|
||||
# alias ta="za"
|
||||
#
|
||||
# # alias zs="zellij setup --dump-config > $HOME/.config/zellij/config.yaml"
|
||||
# fi
|
||||
|
||||
# Function to get the IP address
|
||||
get_ip() {
|
||||
ip a | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | cut -d/ -f1 | head -n 1
|
||||
|
@ -585,31 +608,6 @@ if command_exists hugo; then
|
|||
alias hs='hugo server -D --noHTTPCache --disableFastRender' # --bind "$(get_ip)"'
|
||||
fi
|
||||
|
||||
# Check if php is available, then create the alias
|
||||
# if command_exists php; then
|
||||
# alias phprun="php artisan serve --host=$(get_ip) --port=8000"
|
||||
# fi
|
||||
|
||||
# Check if npm is available, then create the alias
|
||||
# if command_exists npm; then
|
||||
# npmrun() {
|
||||
# npmrun_help() {
|
||||
# echo "Usage: npmrun [environment] [optional:port]"
|
||||
# echo " environment: The npm environment you want to run (e.g. dev)"
|
||||
# echo " port: Port to use (default: 8000)"
|
||||
# return
|
||||
# }
|
||||
# if [[ "$1" == "--help" || "$1" == "-h" ]]; then
|
||||
# npmrun_help
|
||||
# return
|
||||
# fi
|
||||
#
|
||||
# local env="$1"
|
||||
# local port="${2:-8080}"
|
||||
#
|
||||
# npm run "$env" -- --host="$(get_ip)" --port="$port"
|
||||
# }
|
||||
# fi
|
||||
missing() {
|
||||
local e=(
|
||||
bash
|
||||
|
|
34
.zshrc
34
.zshrc
|
@ -351,3 +351,37 @@ main() {
|
|||
if check_root; then
|
||||
main
|
||||
fi
|
||||
|
||||
resolve() {
|
||||
local quiet=false
|
||||
if [[ "$1" == "-q" ]]; then
|
||||
quiet=true
|
||||
shift
|
||||
fi
|
||||
|
||||
local ip="$1"
|
||||
local server="$2"
|
||||
local dig_out
|
||||
dig_out=$(command dig +noall +answer -x "$ip" ${server:+@$server} 2>/dev/null)
|
||||
|
||||
local line ptr hostname time
|
||||
line=$(grep 'PTR' <<<"$dig_out")
|
||||
ptr=$(awk '{print $4}' <<<"$line")
|
||||
time=$(awk '{print $2}' <<<"$dig_out")
|
||||
hostname=$(awk '{print $5}' <<<"$line" | sed 's/\.$//')
|
||||
|
||||
if $quiet; then
|
||||
[[ -n "$hostname" ]] && echo "$hostname"
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -n "$hostname" ]]; then
|
||||
# ✅ resolved
|
||||
printf "✅ ${BOLD}${GREEN}%s${NC} \033[1;90m%s${NC} \033[32m%s${NC} \033[2m%s ms${NC}\n" \
|
||||
"$ptr" "$ip" "$hostname" "$time"
|
||||
else
|
||||
# ❌ not resolved
|
||||
printf "❌ \033[1;31m%s${NC} \033[1;90m%s${NC} \033[1;31mNOT FOUND${NC} \033[2m%s ms\033[0m\n" \
|
||||
"PTR" "$ip" "${time:-0}"
|
||||
fi
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue