aboutsummaryrefslogtreecommitdiff
path: root/config/zsh/aliases/dev.zsh
blob: fa0bf5cb95ca60079f98062a72f357797e61fcbe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
alias remi="wyrd $REMINDER_FILE";

alias aws="docker run --rm -it amazon/aws-cli"

alias pop_run="sh -c 'cd ~/dev/pop && just run'"

# nix shell with zsh
nix-zsh() { nix-shell --run "WITH_NIX_PREFIX='${NX_PREFIX:-':'}' zsh" "$@"; }

# Gitignore locally per-project
# Eg - gitignore-locally flake.nix flake.lock
gitignore-locally() {
  git add --intent-to-add "$@";
  git update-index --assume-unchanged "$@";
}

# :: Filename Pattern Replacetext
far() {
  local file_r="$1"; shift;
  local matcher_r="$1"; shift;
  local result="$1"; shift;
  fd "$file_r" | sad "$matcher_r" "$result" -p diff-so-fancy "$@";
}

get_node_script_runner() {
  # TODO: Check .engines.*
  # jq -r .engines.pnpm package.json
  if [[ -f ./yarn.json ]]; then echo "yarn";
  elif [[ -f ./bun.lockb ]]; then echo "bun run";
  elif [[ -f ./pnpm-lock.yaml ]]; then echo "pnpm";
  else echo "npm run"; fi;
}

# Npm run key binding
# local commands=$(node -e 'const pkg = require("./package.json"); Object.entries(pkg.scripts || {}).map(([key, value]) => console.log(`${key}\t\t\t"${value}"`))');
# local result=$(echo -e "$commands" | fzf | cut -f1);
p__run_npm_script() {
  [[ ! -f "package.json" ]] && return 1;

  local result=$(cat package.json | jq -r '.scripts | to_entries | map([.key, .value] | join("\t\t\t")) | .[]' | fzf | cut -f1);
  [[ -z "$result" ]] && return 1;

  print -Rz - "$(get_node_script_runner) $result ";
  zle send-break
}

zle -N p__run_npm_script;
bindkey '^B' p__run_npm_script;

fix-interpreter() {
  nix-shell -p patchelf --run "patchelf --set-interpreter \$(patchelf --print-interpreter \$(which mkdir)) $@"
}