-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.nu
More file actions
129 lines (108 loc) · 3.7 KB
/
Copy pathconfig.nu
File metadata and controls
129 lines (108 loc) · 3.7 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# See https://www.nushell.sh/book/configuration.html
#
# This file is loaded after env.nu and before login.nu
#
# You can open this file in your default editor using:
# config nu
$env.config.show_banner = false
$env.config.buffer_editor = 'code'
$env.path ++= ['/usr/local/bin', '/opt/homebrew/bin']
$env.PROMPT_COMMAND_RIGHT = ""
$env.PROMPT_COMMAND = {|| (echo $env.PWD | split row "/" | last) }
$env.PROMPT_INDICATOR = ' % '
$env.computer_type = 'home' # 'work' | 'home'
let workspace_path = '~/workspace' | path expand
let worktrees_path = $workspace_path | path join 'worktrees';
let dotfiles_path = $workspace_path | path join 'dotfiles';
let brewfile_path = $dotfiles_path | path join $"brewfile.($env.computer_type).rb";
# https://matthiasportzel.com/brewfile/
def _bbic [--cleanup (-c)] {
brew update
brew bundle install --file=($brewfile_path) ...(if $cleanup { [--cleanup --force] } else { [] })
brew upgrade
}
def _new_ts_project [] {
asdf set nodejs 24.11.1
yarn init -2
"nodeLinker: node-modules\n" | save --force .yarnrc.yml
yarn
yarn add -D typescript @tsconfig/node24 prettier @types/node@24
echo `{
"semi": true,
"trailingComma": "all",
"singleQuote": true
}
` | save --force .prettierrc
echo `{
"$schema": "https://www.schemastore.org/tsconfig",
"extends": "@tsconfig/node24",
"compilerOptions": {
"noEmit": true,
"rewriteRelativeImportExtensions": true,
"erasableSyntaxOnly": true,
"verbatimModuleSyntax": true
}
}
` | save --force tsconfig.json
echo `.yarn` | save --force .prettierignore
open ./package.json
| upsert scripts.format 'prettier --write --ignore-unknown .'
| save --force ./package.json
yarn format
}
def _main-git-branch [] {
git branch -r
| lines
| where ($it | str trim | str starts-with 'origin/HEAD')
| first
| parse '{_}/{_} -> {_}/{main_branch}'
| first
| get main_branch
}
def _start-feature [feature_name: string, --dry (-d), --from-current (-c)] {
let repo_name: string = git config --get remote.origin.url | path basename;
mut branch_name = $feature_name;
let folder = ($worktrees_path | path join $"($feature_name)--($repo_name)");
if $env.computer_type == 'work' {
$branch_name = $"users/maburson/($branch_name)";
}
let main_git_branch = if $from_current {
git branch --show-current
} else {
_main-git-branch
}
let command = $"git worktree add -b ($branch_name) ($folder) ($main_git_branch)"
print $command;
if $dry == false {
# nu -e $command |
git worktree add -b $branch_name $folder $main_git_branch
code $folder
} else {
print { "repo_name": $repo_name, "branch_name": $branch_name, "folder": $folder, "main_git_branch": $main_git_branch}
}
}
def _wto [] {
ls $worktrees_path | each {|folder| $folder.name | path basename }
}
def _wt [branch?: string@_wto, --all (-a)] {
if $all and ($branch != null) {
print -e "Pass either a branch or --all, not both"
} else if $all {
_wto | each {|b| code ($worktrees_path | path join $b) }
} else if ($branch != null) {
code ($worktrees_path | path join $branch)
} else {
print -e "Pass a branch name or --all"
}
}
# https://github.com/Schniz/fnm/issues/463#issuecomment-4381417804
if not (which fnm | is-empty) {
^fnm env --json | from json | load-env
$env.PATH = $env.PATH | prepend ($env.FNM_MULTISHELL_PATH | path join (if $nu.os-info.name == 'windows' {''} else {'bin'}))
$env.config.hooks.env_change.PWD = (
$env.config.hooks.env_change.PWD? | append {
condition: {|| ['.nvmrc' '.node-version', 'package.json'] | any {|el| $el | path exists}}
code: {|| ^fnm use --install-if-missing --silent-if-unchanged}
}
)
}