sh_config.sh 9.3 KB

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