sh_config.sh 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. alias sync_config_file='wget https://git.tianyunperfect.cn/tianyunperfect/sync/raw/master/sh_config.sh -O ~/.sh_config.sh'
  2. # 快捷命令
  3. ## 未分类
  4. alias ll='ls -alh --time-style="+%Y-%m-%d %H:%I:%S"'
  5. #du -sh * 2>/dev/null | sort -hr
  6. alias du-sh='du -sh * 2>/dev/null | sort -hr'
  7. alias sourcevenv='source venv/bin/activate'
  8. alias weather='curl wttr.in/beijing'
  9. alias dust1='dust -d 1'
  10. function gittagpush() {
  11. if [ $# -ne 2 ]; then
  12. echo "需要两个参数: <变量1> <变量2>"
  13. return 1
  14. fi
  15. git tag -a $1 -m "$2"
  16. git push origin $1
  17. }
  18. alias gittags='git --no-pager tag -l -n'
  19. function reloadrc() {
  20. if [[ "$0" =~ "zsh" ]]
  21. then
  22. echo "正在使用zsh"
  23. source ~/.zshrc
  24. else
  25. echo "正在使用bash"
  26. source ~/.bashrc
  27. fi
  28. }
  29. ## k8s
  30. function k8s-getnamespace() {
  31. kubectl config view | grep namespace
  32. }
  33. function k8s-setnamespace() {
  34. k8s-getnamespace
  35. kubectl config set-context --current --namespace="$1"
  36. }
  37. function k8s-getpod() {
  38. k8s-getnamespace
  39. # 如果有参数,则过滤
  40. if [ ! -z "$1" ]; then
  41. kubectl get pods -o wide | grep "$1"
  42. else
  43. kubectl get pods -o wide
  44. fi
  45. }
  46. alias k8s-descpods='kubectl describe pods'
  47. function k8s-getlog() {
  48. k8s-getnamespace
  49. podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
  50. kubectl logs --tail=300 -f "${podName}"
  51. }
  52. function k8s-getlogbase() {
  53. k8s-getnamespace
  54. podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
  55. kubectl logs -c base-jre --tail=300 -f "${podName}"
  56. }
  57. alias k8s-delpod='kubectl delete pod ${1} --force'
  58. function k8s-inpod() {
  59. k8s-getnamespace
  60. podName=$(kubectl get pods -o wide | grep "${1}" | awk '{print $1}')
  61. kubectl exec -it "${podName}" -- /bin/bash
  62. }
  63. alias k8s-topnodes='kubectl top node ${1}'
  64. alias k8s-toppods='kubectl top pod ${1}'
  65. alias k8s-getsvc='kubectl get svc'
  66. alias k8s-descsvc='kubectl describe svc'
  67. alias k8s-deldeployment='kubectl delete deployment'
  68. alias k8s-getdeployment='kubectl get deployment'
  69. alias k8s-descdeployment='kubectl describe deployment'
  70. alias k8s-getdeploymentgrep='kubectl get deployment | grep'
  71. alias k8s-getingress='kubectl get ingress'
  72. alias k8s-descingress='kubectl describe ingress'
  73. alias k8s-getingressgrep='kubectl get ingress | grep'
  74. ## docker
  75. alias docker-rm-all-image='docker rmi $(docker images -q)'
  76. alias docker-rm-all-docker='docker rm $(docker ps -a -q)'
  77. alias docker-show-image-prune='docker image ls -f dangling=true'
  78. alias docker-image-prune='docker image prune -a'
  79. alias dkstats='docker stats'
  80. alias dkps='docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
  81. alias dkpsa='docker ps -a --format "table {{.ID}}\t{{.Names}}\t{{.Ports}}"'
  82. alias dkrm='docker rm -f $1'
  83. alias dkrmi='docker rmi -f $1'
  84. alias dkimage='docker images --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}\t{{.Size}}"'
  85. alias dkip='docker inspect --format="{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" $(docker ps -aq)'
  86. alias dkin='docker exec -it $1 /bin/bash'
  87. alias dklog='docker logs -n 300 -f $1'
  88. alias dkinspect='docker inspect $1'
  89. ## go
  90. alias gobuildwinexe='GOOS=windows GOARCH=amd64 go build -o $1.exe $1.go'
  91. alias gobuildlinuxexe='GOOS=linux GOARCH=amd64 go build -o $1 $1.go'
  92. alias gobuildmacexe='GOOS=darwin GOARCH=amd64 go build -o $1 $1.go'
  93. ## version
  94. alias pythonversion='python --version'
  95. alias javaversion='java -version'
  96. alias nodeversion='node -v'
  97. alias centosversion='cat /etc/os-release'
  98. alias ubuntuversion='cat /etc/lsb-release'
  99. alias goversion='go version'
  100. ## ip查看
  101. alias ipremote='curl cip.cc'
  102. function iplocal() {
  103. # 如果是mac 过滤 en0,如果是linux 过滤 eth0
  104. if [[ "$OSTYPE" == "darwin"* ]]; then
  105. ifconfig en0 | grep inet | grep -v inet6
  106. else
  107. ifconfig eth0 | grep inet | grep -v inet6
  108. fi
  109. }
  110. ## 进程相关
  111. alias psgrep='ps aux | grep -v grep | grep'
  112. alias killport='kill -9 $(lsof -t -i:$1)'
  113. alias ps-mem-top6='ps aux --sort=-%mem | awk '\''{print $2, $11, $4, $6/1024 "MB"}'\'' | head -n 6'
  114. # node
  115. alias npminstall='npm install -g --registry=https://registry.npmmirror.com '
  116. # python
  117. alias pipinstall='pip install $1 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com'
  118. # 文件查找相关
  119. function findByName() {
  120. local pattern=$1
  121. find . -name "*$pattern*"
  122. }
  123. function findByContent() {
  124. local pattern=$2
  125. local dir=$1
  126. find $dir -type f -exec grep -l "$pattern" {} +
  127. }
  128. # 备份
  129. function tar_back()
  130. {
  131. time=$(date "+%Y-%m-%d_%H_%M_%S")
  132. tar -zcvf "${1}".${time}.tgz "$1"
  133. ll -h ${1}.${time}.tgz
  134. }
  135. pid-cmd-centos(){
  136. sudo ls -l /proc/$1/cwd | awk '{print $11}'
  137. sudo cat /proc/$1/cmdline
  138. echo ''
  139. }
  140. pid-cmd-ubuntu() {
  141. ls -l /proc/"$1"/cwd | awk '{print $11}'
  142. tr '\0' ' ' </proc/"$1"/cmdline; echo ""
  143. }
  144. function echo-arthas-install() {
  145. echo '
  146. # 判断是否存在 ~/arthas-boot.jar,如果不存在则下载
  147. if [ ! -f ~/arthas-boot.jar ]; then
  148. ( cd ~ && curl -O https://arthas.aliyun.com/arthas-boot.jar )
  149. fi
  150. # 判断是否在k8s里面
  151. if [[ ! -z "$KUBERNETES_SERVICE_HOST" && ! -z "$KUBERNETES_SERVICE_PORT" ]]; then
  152. echo "Running in Kubernetes environment"
  153. java -jar ~/arthas-boot.jar 1 --options json-format=true
  154. else
  155. echo "Not running in Kubernetes environment"
  156. java -jar ~/arthas-boot.jar --options json-format=true
  157. fi
  158. '
  159. }
  160. alias cparthas='echo-arthas-install | pbcopy'
  161. function curl-form() {
  162. curl -d "$2" "$1"
  163. }
  164. function watch-cpudiskmemory() {
  165. watch -n 1 '
  166. echo "===CPU占用摘要:"
  167. top -bn 1 -i -c | grep Cpu
  168. echo "
  169. ===内存占用摘要:"
  170. free -h
  171. echo "
  172. ===磁盘占用摘要:"
  173. df -h /'
  174. }
  175. #123
  176. function vimrc() {
  177. if [[ "$SHELL" =~ "zsh" ]]
  178. then
  179. code ~/.zshrc
  180. else
  181. code ~/.bashrc
  182. fi
  183. }
  184. merge_video_audio() {
  185. if [ "$#" -ne 3 ]; then
  186. echo "错误:参数数量不正确!"
  187. echo "用法:merge_video_audio video.mp4 audio.mp3 output.mp4"
  188. return 1
  189. fi
  190. ffmpeg -i "$1" -i "$2" -c:v copy -c:a copy "$3"
  191. }
  192. rm-all() {
  193. find . -name $1 | xargs -I {} rm -rf {}
  194. }
  195. ### mysql
  196. function echo-mysql-tables() {
  197. echo 'SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = DATABASE();'
  198. }
  199. function echo-mysql-table-size() {
  200. 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;'
  201. }
  202. function echo-mysql-db-size() {
  203. 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;'
  204. }
  205. function echo-npm() {
  206. echo '
  207. npm i webpack # 在module文件中安装
  208. npm i webpack -S # --save 常用,添加到package
  209. npm i webpack -D # --save-dev
  210. npm i webpack -g --registry=https://registry.npmmirror.com # 全局
  211. npm un webpack -g
  212. yarn add react
  213. yarn remove react
  214. yarn global add umi
  215. '
  216. }
  217. concat_params() {
  218. # 获取传入的参数个数
  219. num_params=$#
  220. # 判断参数个数是否大于等于1
  221. if [ $num_params -ge 1 ]; then
  222. # 使用循环遍历参数,并拼接在一起
  223. concat_str="$1"
  224. for ((i=2; i<=$num_params; i++)); do
  225. concat_str+="%20${!i}"
  226. done
  227. # 打印拼接后的字符串
  228. echo "$concat_str"
  229. else
  230. echo "没有传入参数"
  231. fi
  232. }
  233. function url_encode() {
  234. echo "$1" | sed 's/ /%20/g'
  235. }
  236. function bing() {
  237. ## 如果是windows系统,则使用start,否则使用open,后面的参数可以有多个空格
  238. if [[ "$OSTYPE" == "msys"* ]]; then
  239. search_query=$(concat_params "$@")
  240. start "https://www.bing.com/search?q=$search_query"
  241. else
  242. search_query=""
  243. for query in "$@"; do
  244. search_query+=" $query"
  245. done
  246. search_query=$(url_encode "$search_query")
  247. open "https://www.bing.com/search?q=${search_query}"
  248. fi
  249. }
  250. function mvn_clean_package() {
  251. mvn clean package -Dmaven.test.skip=true
  252. }
  253. ## ska快捷
  254. function ska_push_dev(){
  255. skaffold run -p dev --tail
  256. }
  257. function mvn_push_dev(){
  258. mvn_clean_package
  259. ska_push_dev
  260. }
  261. function mvn_push_test() {
  262. mvn_clean_package
  263. skaffold build -p test -n aimptest
  264. }
  265. function mvn_clean_deploy() {
  266. mvn clean deploy -Dmaven.test.skip=true
  267. }
  268. function show_all_local_ip(){
  269. arp -a
  270. }
  271. alias nodels='fnm ls'
  272. alias nodeuse='fnm use'
  273. alias nodedefault='fnm default'
  274. alias nodeinstall='fnm install'
  275. alias nodelsremote='fnm ls-remote'
  276. alias nodeuninstall='fnm uninstall'
  277. alias catnodeversion='node --version > .node-version'
  278. alias yarnglobaladd='yarn global add'
  279. alias yarnglobalremove='yarn global remove'
  280. alias yarnadd='yarn add'
  281. alias yarnremove='yarn remove'
  282. alias yarninstall='yarn install'
  283. function echosync() {
  284. echo '
  285. source <(curl -s https://git.tianyunperfect.cn/tianyunperfect/sync/raw/master/sh_config.sh)
  286. '
  287. }
  288. alias settitle='wezterm cli set-tab-title '
  289. function btm_linux(){
  290. if [ ! -f "$HOME/btm" ]; then
  291. wget https://tianyunperfect1.oss-cn-beijing.aliyuncs.com/20/2024/btm/btm -O ~/btm
  292. chmod +x ~/btm
  293. fi
  294. ~/btm --process_memory_as_value
  295. }