Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

95 rindas
2.4KB

  1. function h () {
  2. grep "$1" ~/.bash_history
  3. }
  4. function wttr () {
  5. if [[ $# -eq 0 ]] ; then
  6. curl wttr.in/Berlin?format=4
  7. else
  8. curl wttr.in/"$1"
  9. fi
  10. }
  11. ## netstat without netstat
  12. # https://staaldraad.github.io/2017/12/20/netstat-without-netstat/
  13. function _netstat() {
  14. awk 'function hextodec(str,ret,n,i,k,c){
  15. ret = 0
  16. n = length(str)
  17. for (i = 1; i <= n; i++) {
  18. c = tolower(substr(str, i, 1))
  19. k = index("123456789abcdef", c)
  20. ret = ret * 16 + k
  21. }
  22. return ret
  23. }
  24. function getIP(str,ret){
  25. ret=hextodec(substr(str,index(str,":")-2,2));
  26. for (i=5; i>0; i-=2) {
  27. ret = ret"."hextodec(substr(str,i,2))
  28. }
  29. ret = ret":"hextodec(substr(str,index(str,":")+1,4))
  30. return ret
  31. }
  32. NR > 1 {{if(NR==2)print "Local - Remote";local=getIP($2);remote=getIP($3)}{print local" - "remote}}' /proc/net/tcp
  33. }
  34. function _rip_audio() {
  35. if (("$#" != 1)); then
  36. echo "source is missing..."
  37. else
  38. youtube-dl --prefer-ffmpeg --embed-thumbnail --add-metadata --metadata-from-title "%(artist)s - %(title)s" --audio-quality 0 --audio-format mp3 --extract-audio "$1"
  39. fi
  40. }
  41. function aur() {
  42. if (("$#" != 1)); then
  43. echo "source is missing..."
  44. else
  45. cd ~/aur
  46. git clone https://aur.archlinux.org/"$1".git
  47. cd $1
  48. makepkg
  49. fi
  50. }
  51. function awsenv() {
  52. if (("$#" != 1)); then
  53. cmp --silent ~/.aws/credentials ~/.aws/credentials.prod && echo "your're using PROD" || echo "you're using TEST"
  54. elif [ "$1" = "prod" ]; then
  55. cp ~/.aws/credentials.prod ~/.aws/credentials
  56. elif [ "$1" = "test" ]; then
  57. cp ~/.aws/credentials.test ~/.aws/credentials
  58. fi
  59. }
  60. function redis-ping() {
  61. # ping a redis server at any cost
  62. redis-cli -h $1 ping 2>/dev/null || \
  63. echo $((printf "PING\r\n";) | nc $1 6379 2>/dev/null || \
  64. exec 3<>/dev/tcp/$1/6379 && echo -e "PING\r\n" >&3 && head -c 7 <&3)
  65. }
  66. function j() {
  67. if [ "$#" -eq 1 ]; then
  68. docker exec -ti $(docker ps --filter "Name=$1" --format "{{.Names}}") /bin/sh
  69. fi
  70. }
  71. # delete instead of rm -rf
  72. del() {
  73. # mv to trash
  74. mkdir -p ~/.Trash
  75. mv "$@" ~/.Trash/
  76. # delete files older than 5 days
  77. find ~/.Trash -type f -mtime +5 -delete
  78. # delete empty directories
  79. find ~/.Trash -type d -empty -delete
  80. }