tianyun 8 月之前
父节点
当前提交
4e990ede27
共有 1 个文件被更改,包括 149 次插入144 次删除
  1. 149 144
      sh_config.sh

+ 149 - 144
sh_config.sh

@@ -1,5 +1,5 @@
 # path去重
-export PATH=`echo $PATH | tr ':' '\n' | cat -n | sort -k2,2 -k1,1n | uniq -f1 | sort -k1,1n | cut -f2- | tr '\n' ':'`
+export PATH=$(echo $PATH | tr ':' '\n' | cat -n | sort -k2,2 -k1,1n | uniq -f1 | sort -k1,1n | cut -f2- | tr '\n' ':')
 
 alias sync_config_file='wget https://git.tianyunperfect.cn/tianyunperfect/sync/raw/master/sh_config.sh -O ~/.sh_config.sh && source ~/.sh_config.sh'
 # 快捷命令
@@ -14,61 +14,61 @@ alias weather='curl wttr.in/beijing'
 alias dust1='dust -d 1'
 
 function gittagpush() {
-    if [ $# -ne 2 ]; then
-        echo "需要两个参数: <变量1> <变量2>"
-        return 1
-    fi
+	if [ $# -ne 2 ]; then
+		echo "需要两个参数: <变量1> <变量2>"
+		return 1
+	fi
 
-    git tag -a $1 -m "$2"
-    git push origin $1
+	git tag -a $1 -m "$2"
+	git push origin $1
 }
 alias gittags='git --no-pager tag -l -n'
 
 function reloadrc() {
-    if [ -n "$ZSH_VERSION" ]; then
-        echo "正在使用zsh"
-        source ~/.zshrc
-    elif [ -n "$BASH_VERSION" ]; then
-        echo "正在使用bash"
-        source ~/.bashrc
-    else
-        echo "无法确定当前 Shell 类型"
-    fi
+	if [ -n "$ZSH_VERSION" ]; then
+		echo "正在使用zsh"
+		source ~/.zshrc
+	elif [ -n "$BASH_VERSION" ]; then
+		echo "正在使用bash"
+		source ~/.bashrc
+	else
+		echo "无法确定当前 Shell 类型"
+	fi
 }
 
 ## k8s
 function k8s-getnamespace() {
-    kubectl config view | grep namespace
+	kubectl config view | grep namespace
 }
 function k8s-setnamespace() {
-    k8s-getnamespace
-    kubectl config set-context --current --namespace="$1"
+	k8s-getnamespace
+	kubectl config set-context --current --namespace="$1"
 }
 function k8s-getpod() {
-    k8s-getnamespace
-    # 如果有参数,则过滤
-    if [ ! -z "$1" ]; then
-        kubectl get pods -o wide | grep "$1"
-    else
-        kubectl get pods -o wide
-    fi
+	k8s-getnamespace
+	# 如果有参数,则过滤
+	if [ ! -z "$1" ]; then
+		kubectl get pods -o wide | grep "$1"
+	else
+		kubectl get pods -o wide
+	fi
 }
 alias k8s-descpods='kubectl describe pods'
 function k8s-getlog() {
-    k8s-getnamespace
-    podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
-    kubectl logs --tail=300 -f "${podName}"
+	k8s-getnamespace
+	podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
+	kubectl logs --tail=300 -f "${podName}"
 }
 function k8s-getlogbase() {
-    k8s-getnamespace
-    podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
-    kubectl logs -c base-jre --tail=300 -f "${podName}"
+	k8s-getnamespace
+	podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
+	kubectl logs -c base-jre --tail=300 -f "${podName}"
 }
 alias k8s-delpod='kubectl delete pod ${1} --force'
 function k8s-inpod() {
-    k8s-getnamespace
-    podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
-    kubectl exec -it "${podName}" -- /bin/bash
+	k8s-getnamespace
+	podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
+	kubectl exec -it "${podName}" -- /bin/bash
 }
 
 alias k8s-topnodes='kubectl top node ${1}'
@@ -87,8 +87,6 @@ alias k8s-getingress='kubectl get ingress'
 alias k8s-descingress='kubectl describe ingress'
 alias k8s-getingressgrep='kubectl get ingress | grep'
 
-
-
 ## docker
 alias docker-rm-all-image='docker rmi $(docker images -q)'
 alias docker-rm-all-docker='docker rm $(docker ps -a -q)'
@@ -102,10 +100,10 @@ alias dkrmi='docker rmi -f $1'
 alias dkimage='docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}"'
 alias dkip='docker inspect --format="{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $(docker ps -aq)'
 function dkin() {
-    docker exec -it "$1" bash
+	docker exec -it "$1" bash
 }
-function dkinsh(){
-    docker exec -it $1 sh
+function dkinsh() {
+	docker exec -it $1 sh
 }
 alias dklog='docker logs -n 300 -f $1'
 alias dkinspect='docker inspect $1'
@@ -123,16 +121,15 @@ alias centosversion='cat /etc/os-release'
 alias ubuntuversion='cat /etc/lsb-release'
 alias goversion='go version'
 
-
 ## ip查看
 alias ipremote='curl cip.cc'
 function iplocal() {
-    # 如果是mac 过滤 en0,如果是linux 过滤 eth0
-    if [[ "$OSTYPE" == "darwin"* ]]; then
-        ifconfig en0 | grep inet | grep -v inet6
-    else
-        ifconfig eth0 | grep inet | grep -v inet6
-    fi
+	# 如果是mac 过滤 en0,如果是linux 过滤 eth0
+	if [[ "$OSTYPE" == "darwin"* ]]; then
+		ifconfig en0 | grep inet | grep -v inet6
+	else
+		ifconfig eth0 | grep inet | grep -v inet6
+	fi
 }
 
 ## 进程相关
@@ -148,37 +145,35 @@ alias pipinstall='pip install $1 -i http://mirrors.aliyun.com/pypi/simple/ --tru
 
 # 文件查找相关
 function findByName() {
-  local pattern=$1
-  find . -name "*$pattern*"
+	local pattern=$1
+	find . -name "*$pattern*"
 }
 function findByContent() {
-  local pattern=$2
-  local dir=$1
-  find $dir -type f -exec grep -l "$pattern" {} +
+	local pattern=$2
+	local dir=$1
+	find $dir -type f -exec grep -l "$pattern" {} +
 }
 
 # 备份
-function tar_back()
-{
-time=$(date "+%Y-%m-%d_%H_%M_%S")
-tar -zcvf "${1}".${time}.tgz "$1"
-ll -h ${1}.${time}.tgz
+function tar_back() {
+	time=$(date "+%Y-%m-%d_%H_%M_%S")
+	tar -zcvf "${1}".${time}.tgz "$1"
+	ll -h ${1}.${time}.tgz
 }
 
-
-pid-cmd-centos(){
-sudo ls -l /proc/$1/cwd  | awk '{print $11}'
-sudo cat /proc/$1/cmdline
-echo ''
+pid-cmd-centos() {
+	sudo ls -l /proc/$1/cwd | awk '{print $11}'
+	sudo cat /proc/$1/cmdline
+	echo ''
 }
 pid-cmd-ubuntu() {
-  ls -l /proc/"$1"/cwd | awk '{print $11}'
-  tr '\0' ' ' </proc/"$1"/cmdline; echo ""
+	ls -l /proc/"$1"/cwd | awk '{print $11}'
+	tr '\0' ' ' </proc/"$1"/cmdline
+	echo ""
 }
 
-
 function echo-arthas-install() {
-    echo '
+	echo '
     # 判断是否存在 ~/arthas-boot.jar,如果不存在则下载
     if [ ! -f ~/arthas-boot.jar ]; then
         ( cd ~ && curl -O https://arthas.aliyun.com/arthas-boot.jar )
@@ -196,13 +191,12 @@ function echo-arthas-install() {
 }
 alias cparthas='echo-arthas-install | pbcopy'
 
-
 function curl-form() {
-    curl -d "$2" "$1"
+	curl -d "$2" "$1"
 }
 
 function watch-cpudiskmemory() {
-    watch -n 1 '
+	watch -n 1 '
     echo "===CPU占用摘要:"
     top -bn 1 -i -c | grep Cpu
 
@@ -216,41 +210,40 @@ function watch-cpudiskmemory() {
 }
 #123
 function vimrc() {
-    if [[ "$SHELL" =~ "zsh" ]]
-    then
-      code ~/.zshrc
-    else
-      code ~/.bashrc
-    fi
+	if [[ "$SHELL" =~ "zsh" ]]; then
+		code ~/.zshrc
+	else
+		code ~/.bashrc
+	fi
 }
 
 merge_video_audio() {
-    if [ "$#" -ne 3 ]; then
-        echo "错误:参数数量不正确!"
-        echo "用法:merge_video_audio video.mp4 audio.mp3 output.mp4"
-        return 1
-    fi
+	if [ "$#" -ne 3 ]; then
+		echo "错误:参数数量不正确!"
+		echo "用法:merge_video_audio video.mp4 audio.mp3 output.mp4"
+		return 1
+	fi
 
-    ffmpeg -i "$1" -i "$2" -c:v copy -c:a copy "$3"
+	ffmpeg -i "$1" -i "$2" -c:v copy -c:a copy "$3"
 }
 
 rm-all() {
-    find . -name $1 | xargs -I {} rm -rf {}
+	find . -name $1 | xargs -I {} rm -rf {}
 }
 
 ### mysql
 function echo-mysql-tables() {
-    echo 'SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = DATABASE();'
+	echo 'SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = DATABASE();'
 }
 function echo-mysql-table-size() {
-    echo 'select table_name,concat(round(sum(DATA_LENGTH/1024/1024),2),"MB") as data from information_schema.TABLES where  table_schema =(SELECT DATABASE()) group by table_name;'
+	echo 'select table_name,concat(round(sum(DATA_LENGTH/1024/1024),2),"MB") as data from information_schema.TABLES where  table_schema =(SELECT DATABASE()) group by table_name;'
 }
 function echo-mysql-db-size() {
-    echo 'select table_schema,concat(round(sum(DATA_LENGTH/1024/1024),2),"MB") as data from information_schema.TABLES  where table_schema not in ("information_schema","mysql","performance_schema","sys")  group by table_schema;'
+	echo 'select table_schema,concat(round(sum(DATA_LENGTH/1024/1024),2),"MB") as data from information_schema.TABLES  where table_schema not in ("information_schema","mysql","performance_schema","sys")  group by table_schema;'
 }
 
 function echo-npm() {
-    echo '
+	echo '
                    npm i webpack				 # 在module文件中安装
                    npm i webpack -S 		# --save     常用,添加到package
                    npm i webpack -D 		# --save-dev
@@ -263,70 +256,67 @@ function echo-npm() {
                    '
 }
 
-
 concat_params() {
-  # 获取传入的参数个数
-  num_params=$#
-
-  # 判断参数个数是否大于等于1
-  if [ $num_params -ge 1 ]; then
-    # 使用循环遍历参数,并拼接在一起
-    concat_str="$1"
-    for ((i=2; i<=$num_params; i++)); do
-      concat_str+="%20${!i}"
-    done
-
-    # 打印拼接后的字符串
-    echo "$concat_str"
-  else
-    echo "没有传入参数"
-  fi
+	# 获取传入的参数个数
+	num_params=$#
+
+	# 判断参数个数是否大于等于1
+	if [ $num_params -ge 1 ]; then
+		# 使用循环遍历参数,并拼接在一起
+		concat_str="$1"
+		for ((i = 2; i <= $num_params; i++)); do
+			concat_str+="%20${!i}"
+		done
+
+		# 打印拼接后的字符串
+		echo "$concat_str"
+	else
+		echo "没有传入参数"
+	fi
 }
 function url_encode() {
-    echo "$1" | sed 's/ /%20/g'
+	echo "$1" | sed 's/ /%20/g'
 }
 function bing() {
-  ## 如果是windows系统,则使用start,否则使用open,后面的参数可以有多个空格
-  if [[ "$OSTYPE" == "msys"* ]]; then
-    search_query=$(concat_params "$@")
-    start "https://www.bing.com/search?q=$search_query"
-  else
-      search_query=""
-      for query in "$@"; do
-          search_query+=" $query"
-      done
-      search_query=$(url_encode "$search_query")
-    open "https://www.bing.com/search?q=${search_query}"
-  fi
+	## 如果是windows系统,则使用start,否则使用open,后面的参数可以有多个空格
+	if [[ "$OSTYPE" == "msys"* ]]; then
+		search_query=$(concat_params "$@")
+		start "https://www.bing.com/search?q=$search_query"
+	else
+		search_query=""
+		for query in "$@"; do
+			search_query+=" $query"
+		done
+		search_query=$(url_encode "$search_query")
+		open "https://www.bing.com/search?q=${search_query}"
+	fi
 }
 
 function mvn_clean_package() {
-  mvn clean package -Dmaven.test.skip=true
+	mvn clean package -Dmaven.test.skip=true
 }
 
 ## ska快捷
-function ska_push_dev(){
-  skaffold run -p dev --tail
+function ska_push_dev() {
+	skaffold run -p dev --tail
 }
 
-function mvn_push_dev(){
-  mvn_clean_package
-  ska_push_dev
+function mvn_push_dev() {
+	mvn_clean_package
+	ska_push_dev
 }
 function mvn_push_test() {
-  mvn_clean_package
-  skaffold build -p test -n aimptest
+	mvn_clean_package
+	skaffold build -p test -n aimptest
 }
 function mvn_clean_deploy() {
-    mvn clean deploy -Dmaven.test.skip=true
+	mvn clean deploy -Dmaven.test.skip=true
 }
 
-
-function show_all_local_ip(){
-  arp -a
+function show_all_local_ip() {
+	arp -a
 }
 
-
 alias nodels='fnm ls'
 alias nodeuse='fnm use'
 alias nodedefault='fnm default'
@@ -336,43 +326,58 @@ alias nodeuninstall='fnm uninstall'
 
 alias catnodeversion='node --version > .node-version'
 
-
 alias yarnglobaladd='yarn global add'
 alias yarnglobalremove='yarn global remove'
 alias yarnadd='yarn add'
 alias yarnremove='yarn remove'
 alias yarninstall='yarn install'
 
-
 function echosync() {
-echo '
+	echo '
 source <(curl -s https://git.tianyunperfect.cn/tianyunperfect/sync/raw/master/sh_config.sh)
 '
 }
 
 alias settitle='wezterm cli set-tab-title '
 
-function btm_linux(){
-    if [ ! -f "$HOME/btm" ]; then
-        wget https://tianyunperfect1.oss-cn-beijing.aliyuncs.com/20/2024/btm/btm -O ~/btm
-        chmod +x ~/btm
-    fi
+function btm_linux() {
+	if [ ! -f "$HOME/btm" ]; then
+		wget https://tianyunperfect1.oss-cn-beijing.aliyuncs.com/20/2024/btm/btm -O ~/btm
+		chmod +x ~/btm
+	fi
 
-    ~/btm  --process_memory_as_value
+	~/btm --process_memory_as_value
 }
 
 # watch 优化
 alias watch_alias='watch '
 # 函数,每隔2秒执行一次参数命令
 function watch_func() {
-    while true; do
-        clear
-        "$@"
-        sleep 2
-    done
+	while true; do
+		clear
+		"$@"
+		sleep 2
+	done
 }
 
 alias gpu_nvidia='nvidia-smi'
 alias gpu_amd='rocm-smi --showpids -u  -P'
 
-alias iptables_show_all='iptables -t nat -L -n'
+alias iptables_show_all='iptables -t nat -L -n'
+
+# docker-compose up ,如果有参数,则使用-f 文件
+function docker_compose_up() {
+	if [ $# -eq 0 ]; then
+		docker-compose up
+		return
+	fi
+	docker-compose -f "$1" up
+}
+# 同理 docker-compose down
+function docker_compose_down() {
+	if [ $# -eq 0 ]; then
+		docker-compose down
+		return
+	fi
+	docker-compose -f "$1" down
+}