-
Notifications
You must be signed in to change notification settings - Fork 0
/
Justfile
executable file
·137 lines (98 loc) · 3.51 KB
/
Justfile
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
130
131
132
133
134
135
136
137
#! /usr/bin/env just --justfile
_default:
@just --list
# Update all package files
update-packages: update-homebrew update-gems update-pipx update-ports
# Update Homebrew Brewfile
update-homebrew:
#!/usr/bin/env ruby
require "tmpdir"
dump = %x(brew bundle dump --force --file=- --describe).split($/)
lines = Hash.new { |h, k| h[k] = [] }
comment = nil
dump.each do |line|
line.chomp!
if line.start_with?("#")
comment = line
else
key = line.split(" ").first
key = "#{key}-font" if line.include?('"font-')
if comment
lines[key] << "#{line} #{comment}"
comment = nil
else
lines[key] << line
end
end
end
tmpdir = Dir.mktmpdir
File.write(
File.join(tmpdir, "Brewfile"),
lines.keys.map { lines[_1].sort.join("\n") }.join("\n")
)
exec("vimdiff '#{tmpdir}/Brewfile' 'Setup/Brewfile'")
# Update the default Gemfile
update-gems:
#!/usr/bin/env ruby
require "json"
require "net/http"
require "tmpdir"
def fetch(url)
JSON.parse(Net::HTTP.get(URI(url)))["gems"].map { _1["gem"] }
end
def local_gems
%x(gem list --no-versions).split($/)
end
rubys_gems = fetch("https://stdgems.org/default_gems.json") +
fetch("https://stdgems.org/bundled_gems.json")
gems = (local_gems - rubys_gems).map { %Q(gem "#{_1}") }.join("\n")
tmpdir = Dir.mktmpdir
File.write(File.join(tmpdir, "Gemfile"), gems)
exec("vimdiff '#{tmpdir}/Gemfile' 'Setup/Gemfile'")
# Update the default pipx list of files
update-pipx:
#!/usr/bin/env ruby
require "json"
packages = JSON.parse(`pipx list --json`)["venvs"]
result = packages.values.map { |package|
main = package["metadata"]["main_package"]
name = main["package"]
url = main["package_or_url"]
suffix = main["suffix"] unless main["suffix"].nil? || main["suffix"].empty?
deps = main["include_dependencies"]
pip_args = main["pip_args"] unless main["pip_args"].nil? || main["pip_args"].empty?
install = %w[pipx install]
install << url
install << "--include-deps" if main["include_dependencies"]
install.push("--suffix", suffix) if suffix
install.push("--pip-args", pip_args.join(" ")) if pip_args
install = install.join(" ")
inject = package.dig("metadata", "injected_packages").values.group_by { |v|
{"apps" => v["include_apps"], "deps" => v["include_deps"]}
}.values.map { |injectables|
opts = injectables.first
pkg = []
pkg << "--include-apps" if opts["include_apps"]
pkg << "--include-deps" if opts["include_deps"]
injectables.each { |i| pkg << i["package_or_url"].delete(" ") }
["pipx", "inject", name, *pkg]
}.join(" ")
inject = nil if inject.empty?
[install, inject].compact.join(" &&\n ")
}.join("\n")
File.write("Setup/Pipx.fish", result + "\n")
# pipx list --include-injected --json | jq -f Setup/pipx-reinstall.jq > Setup/pipx.fish.new -r
# Update the requested ports
update-ports:
#!/usr/bin/env bash
set -euo pipefail
declare tmp
tmp="$(mktemp -d)/Ports"
port echo requested |
sed -e 's/ */ /' -e 's/\@[^+][^+]*//' -e 's/ $//' -e 's/^/install /' |
sort --ignore-case --unique >"${tmp}"
echo >>"${tmp}"
port select --summary |
awk 'NR > 2 && $2 != "none" { print "select --set", $1, $(NF - 1) }' |
sort --ignore-case --unique >>"${tmp}"
vimdiff "${tmp}" "Setup/Ports"