1
0

aliases.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/bash
  2. # ls
  3. alias l='ls -lFh' # size,show type,human readable
  4. alias la='ls -lAFh' # long list,show almost all,show type,human readable
  5. alias lr='ls -tRFh' # sorted by date,recursive,show type,human readable
  6. alias lt='ls -ltFh' # long list,sorted by date,show type,human readable
  7. alias ll='ls -l' # long list
  8. alias lth='lt | head -16' # latest 15
  9. alias dfh='df -h' # df
  10. # du
  11. alias duh="du -sh * | sort -h"
  12. # export local .env file
  13. alias export-env="export \$(grep -v '^#' .env | xargs -0)"
  14. # docker / podman — only alias to podman if docker CLI isn't installed
  15. if ! command -v docker >/dev/null 2>&1 && command -v podman >/dev/null 2>&1; then
  16. alias docker='podman'
  17. alias docker-compose='podman-compose'
  18. alias dc='docker-compose'
  19. else
  20. alias dc='docker compose'
  21. fi
  22. alias d='docker'
  23. # k8s
  24. alias k='kubectl'
  25. alias kx='kubectx'
  26. # http
  27. alias http-server='python3 -m http.server'
  28. # osx-only aliases
  29. if [[ "$(uname -s)" = 'Darwin' ]]; then
  30. alias get-buffer="$HOME/dotfiles/bin/get-iterm2-buffer"
  31. alias chrome-tabs="$HOME/dotfiles/bin/chrome-tabs"
  32. fi
  33. # node
  34. alias scripts="jq .scripts package.json"
  35. # other bin
  36. alias awsp="$HOME/dotfiles/bin/aws-profile"
  37. # display docker statuses
  38. alias dockerps="docker ps --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}'"
  39. # set terminal title
  40. function title {
  41. echo -ne "\033]0;"$*"\007"
  42. }
  43. alias branchpr="git checkout -b fix/grrowl-\$(date +%s) && gh pr create -w"
  44. # generate password
  45. alias pwgen="openssl rand -base64"
  46. alias rssi="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | egrep -E 'agrCtlRSSI|agrCtlNoise|lastTxRate'"
  47. # dtach
  48. dtach-job() {
  49. if [ -z $2 ]; then
  50. dtach -a $1.dtach
  51. else
  52. dtach -n $1.dtach /bin/bash -c "${@:2} >> $1.log 2>&1"
  53. fi
  54. }
  55. # better watch
  56. alias watchx="watch -cd -n 2"
  57. # easy checkout
  58. checkout() {
  59. if [ -z "$*" ]; then
  60. echo "Needs arg"
  61. return
  62. fi
  63. DIR=$(echo "$@" | grep -Eo '[^/:]+/[^/]+\.git' | sed 's/\.git$//');
  64. git clone "$@" "$HOME/repos/$DIR" || return
  65. cd "$HOME/repos/$DIR" || return
  66. }
  67. alias ac='git diff --staged | head -c $((128 * 1024 * 3)) | llm -m openrouter/openrouter/free '\''Write a concise, imperative-mood git commit message summarizing these changes. Begin with feat, fix, bug, docs, or chore. No preamble or yapping.'\'' | git commit -F -'
  68. alias pbjson="pbpaste | jq -r"
  69. alias pbjsons="pbpaste | jq -sRr '@json'"
  70. alias vscode-server="docker run -it --init -p 3000:3000 -v "$(pwd):/home/workspace:cached" gitpod/openvscode-server"
  71. alias cc='claude --dangerously-skip-permissions --system-prompt "."'
  72. alias ccw='claude --dangerously-skip-permissions --system-prompt "." --tmux -w'
  73. alias t-claude="tmux has-session -t claude-session || tmux new-session -d -s claude-session; tmux attach-session -t claude-session"
  74. alias t-code="tmux has-session -t code-session || tmux new-session -d -s code-session; tmux attach-session -t code-session"
  75. # tt — attach/create the tmux session for the CURRENT dir, matching Zed's naming
  76. # (parent_current via -A). Switches instead of nesting when already inside tmux.
  77. tt() {
  78. local name
  79. name="$(basename "$(dirname "$PWD")")_$(basename "$PWD")"
  80. if [ -n "$TMUX" ]; then
  81. tmux has-session -t "=$name" 2>/dev/null || tmux new-session -d -s "$name"
  82. tmux switch-client -t "=$name"
  83. else
  84. tmux new-session -A -s "$name"
  85. fi
  86. }
  87. # tmux picker: native choose-tree (real tree, '/' filter, live preview, -Z zoom).
  88. # -F colorizes the right-hand descriptive column — the session/window NAME on the
  89. # left is drawn plain by tmux and can't be styled. Three line types handled via
  90. # the pane_format / window_format conditional (else-branch = session line).
  91. ts() {
  92. local h="$HOME" pane win sess fmt
  93. pane="#[fg=magenta]#{pane_current_command}#[default] #[fg=blue]#{s|$h|~|:pane_current_path}#[default]"
  94. win="#[fg=magenta]#{pane_current_command}#[default] #[fg=blue]#{s|$h|~|:pane_current_path}#[default]#{?window_zoomed_flag, #[fg=yellow]Z#[default],}#{?window_active, #[fg=green]●#[default],} #[fg=colour244]#{t/f/%b %d %H#:%M:window_activity}#[default]"
  95. sess="#[fg=yellow]#{session_windows}w#[default] #{?session_attached,#[fg=green]● attached#[default],#[fg=colour244]detached#[default]} #[fg=colour244]#{t/f/%b %d %H#:%M:session_activity}#[default]"
  96. fmt="#{?pane_format,$pane,#{?window_format,$win,$sess}}"
  97. if [ -n "$TMUX" ]; then
  98. tmux choose-tree -Zs -F "$fmt"
  99. else
  100. tmux attach \; choose-tree -Zs -F "$fmt" 2>/dev/null || echo "no tmux sessions"
  101. fi
  102. }
  103. # rerun <cmd...> — re-run a command whenever files under the cwd change, using
  104. # whichever file watcher is installed (watchexec preferred, else entr). Lets the
  105. # same alias work across machines that have one or the other.
  106. if command -v watchexec >/dev/null 2>&1; then
  107. rerun() { watchexec --restart -- "$@"; }
  108. elif command -v entr >/dev/null 2>&1; then
  109. # entr takes the file list on stdin; feed it everything under cwd minus .git
  110. rerun() { find . -type f -not -path '*/.git/*' | entr -r -- "$@"; }
  111. else
  112. rerun() { echo "rerun: install watchexec or entr" >&2; return 127; }
  113. fi