aliases.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. # gw — create a git worktree under .claude/worktrees/<name>, copy in the
  74. # .worktreeinclude (gitignored) files, cd into it, and print its path.
  75. # Git's chatter goes to stderr so stdout is just the path, e.g:
  76. # zed "$(gw new-feature)"
  77. # usage: gw <name> [base-ref] (base-ref defaults to HEAD)
  78. gw() {
  79. local repo name wt
  80. repo=$(git rev-parse --show-toplevel 2>/dev/null) || { echo "gw: not in a git repo" >&2; return 1; }
  81. name=$1
  82. [ -n "$name" ] || { echo "usage: gw <name> [base-ref]" >&2; return 1; }
  83. wt="$repo/.claude/worktrees/$name"
  84. [ -e "$wt" ] && { echo "gw: $wt already exists" >&2; return 1; }
  85. git -C "$repo" worktree add -b "worktree-$name" "$wt" "${2:-HEAD}" >&2 || return
  86. # replicate .worktreeinclude: copy gitignored files matching its patterns
  87. if [ -f "$repo/.worktreeinclude" ]; then
  88. git -C "$repo" ls-files -z --others --ignored --exclude-from=.worktreeinclude \
  89. | while IFS= read -r -d '' f; do
  90. mkdir -p "$(dirname "$wt/$f")"
  91. cp -p "$repo/$f" "$wt/$f"
  92. done
  93. fi
  94. echo "$wt"
  95. cd "$wt"
  96. }
  97. alias t-claude="tmux has-session -t claude-session || tmux new-session -d -s claude-session; tmux attach-session -t claude-session"
  98. alias t-code="tmux has-session -t code-session || tmux new-session -d -s code-session; tmux attach-session -t code-session"
  99. # tt — attach/create the tmux session for the CURRENT dir, matching Zed's naming
  100. # (parent_current via -A). Switches instead of nesting when already inside tmux.
  101. tt() {
  102. local name
  103. name="$(basename "$(dirname "$PWD")")_$(basename "$PWD")"
  104. if [ -n "$TMUX" ]; then
  105. tmux has-session -t "=$name" 2>/dev/null || tmux new-session -d -s "$name"
  106. tmux switch-client -t "=$name"
  107. else
  108. tmux new-session -A -s "$name"
  109. fi
  110. }
  111. # tmux picker: native choose-tree (real tree, '/' filter, live preview, -Z zoom).
  112. # -F colorizes the right-hand descriptive column — the session/window NAME on the
  113. # left is drawn plain by tmux and can't be styled. Three line types handled via
  114. # the pane_format / window_format conditional (else-branch = session line).
  115. ts() {
  116. local h="$HOME" pane win sess fmt
  117. pane="#[fg=magenta]#{pane_current_command}#[default] #[fg=blue]#{s|$h|~|:pane_current_path}#[default]"
  118. 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]"
  119. 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]"
  120. fmt="#{?pane_format,$pane,#{?window_format,$win,$sess}}"
  121. if [ -n "$TMUX" ]; then
  122. tmux choose-tree -Zs -F "$fmt"
  123. else
  124. tmux attach \; choose-tree -Zs -F "$fmt" 2>/dev/null || echo "no tmux sessions"
  125. fi
  126. }
  127. # rerun <cmd...> — re-run a command whenever files under the cwd change, using
  128. # whichever file watcher is installed (watchexec preferred, else entr). Lets the
  129. # same alias work across machines that have one or the other.
  130. if command -v watchexec >/dev/null 2>&1; then
  131. rerun() { watchexec --restart -- "$@"; }
  132. elif command -v entr >/dev/null 2>&1; then
  133. # entr takes the file list on stdin; feed it everything under cwd minus .git
  134. rerun() { find . -type f -not -path '*/.git/*' | entr -r -- "$@"; }
  135. else
  136. rerun() { echo "rerun: install watchexec or entr" >&2; return 127; }
  137. fi