repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: restore of puk.nu

81a53472267724b3429251f809597d0d2b62ad0f

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

neovim/puk.nu

Modified
1 1 #!/usr/bin/env nu
3 3 # TODO:
4 -# treesj for nushell
5 -# setup new nvim-treesitter and nvim-treesitter-textobjects
6 -# clean unspecified plugins
7 4 # XXX use rss feeds of forges to find latest commit
9 6 # an out-of-band plugin manager for neovim.
17 14 let cache_path = nvim --headless --clean +'lua print(vim.fn.stdpath "cache")' +q | complete | get stderr
18 15 let plugins_path = [ $data_path site pack puk opt ] | path join
19 16 let plugin_specs = open puk.plugins.nuon
17 + print 'Installing plugins from puk.plugins.nuon.'
20 18 $plugin_specs | par-each { install-spec $in $plugins_path $cache_path }
19 + print 'Cleaning plugins, that are not part of puk.plugins.nuon.'
20 + clean-plugins $plugins_path $plugin_specs
21 + print 'Generating helptags.'
21 22 nvim --headless -u NONE +'helptags ALL' +q
25 +# check online for fresh commits. Does not actually mutate or update anything.
26 +# updated plugin specs will be written to a new file.
27 +def 'main update' [] {
28 + let plugin_specs = open puk.plugins.nuon
30 + let updated = $plugin_specs |
31 + update commit {
32 + |spec|
33 + let fresh_commit = find-latest-commit $spec
34 + if ($fresh_commit != $spec.commit) {
35 + print $"Found fresh commit for ($spec.name):($fresh_commit)!"
36 + return $fresh_commit
37 + }
38 + return $spec.commit
39 + }
41 + if not ($plugin_specs == $updated) {
42 + $plugin_specs |
43 + merge $updated |
44 + to nuon --indent 2 |
45 + save --force puk.plugins.updated.nuon
46 + print "Written updated puk.plugins into puk.plugins.updated.nuon!"
47 + } else {
48 + print "Nothing to do."
49 + }
52 +# deletes all existing plugins, that are NOT in the specs!
53 +def clean-plugins [
54 + plugins_path: path # folder to install plugins into
55 + plugin_specs: list<any> # all known plugins
56 +] {
57 + ls $plugins_path | each {
58 + | row |
59 + let existing_plugin_name = $row.name | path basename
60 + if ( $plugin_specs | where name == $existing_plugin_name | is-empty) {
61 + print $"Found plugin, that is not part of the specs: ($existing_plugin_name)"
62 + rm --interactive --trash --recursive $row.name
63 + }
64 + }
24 67 # given a plugin spec, and a plugins base install directory, this method generates
25 68 # a new path, that points to the location the plugin should be installed into.
26 69 def make-plugin-path [
48 91 return false
50 93 let commit = open --raw $commit_file_path | str trim
51 - $commit == $spec.commit
94 + return ($commit == $spec.commit)
97 +def find-latest-commit [
98 + spec: record # a plugin to install
99 +] {
100 + let feed = generate-commit-feed-url $spec
101 + let commit = match $spec.source {
102 + github => {
103 + http get $feed | lines | parse --regex "Commit/(?<commit>[a-z0-9]+)" | first | get commit
104 + },
105 + codeberg => { 'TODO' },
106 + srht => { 'TODO' },
107 + _ => { error make {
108 + msg: 'unknown plugin source given'
109 + label: {
110 + text: 'dunno this one'
111 + span: (metadata $spec.source).span
116 + $commit
119 +def generate-commit-feed-url [
120 + spec: record # a plugin to install
121 +] {
122 + let url_format = match $spec.source {
123 + github => { 'https://github.com/{repo}/commits/{branch}.atom' },
124 + codeberg => { 'TODO' },
125 + srht => { 'TODO' },
126 + _ => { error make {
127 + msg: 'unknown plugin source given'
128 + label: {
129 + text: 'dunno this one'
130 + span: (metadata $spec.source).span
135 + $spec | format pattern $url_format
54 138 def generate-download-url [
77 161 let archive_path = [ $cache_path ($spec.name + '.tar.gz') ] | path join
78 162 if ($archive_path | path exists) {
163 + print $"($spec.name) already cached in ($archive_path)"
79 164 return $archive_path
81 166 let url = generate-download-url $spec
99 184 $tmp_path
187 +let allowed_shared_lib_type = match ( sys host | get name ) {
188 + $name if $name =~ 'Windows' => { 'dll' },
189 + $name if $name =~ 'Linux' => { 'so' },
190 + $name if $name =~ 'Mac' => { 'dylib' },
191 + _ => { error make { msg: 'unknown operating system' } },
193 +let allowed_filetypes = [ lua vim scm txt $allowed_shared_lib_type ]
102 195 def install-plugin [
103 196 spec: record # a plugin to install
104 197 folder_path: path # unpacked path to plugin folder
108 201 try { rm --trash --recursive $plugin_path }
109 202 mkdir $plugin_path
110 203 cd $folder_path
111 - let allowed_shared_lib_type = match ( sys host | get name ) {
112 - 'Windows' => { 'dll' },
113 - 'Linux' => { 'so' },
114 - 'Mac' => { 'dylib' },
115 - }
116 - let allowed_filetypes = [ lua vim scm txt $allowed_shared_lib_type ]
117 204 let exclusions = [**/tests/**, **/scripts/**, **/fixtures/**, **/target/release/deps/**]
118 205 glob $"**/*.{($allowed_filetypes | str join ',')}" --exclude $exclusions |
119 206 path relative-to (pwd) |
136 223 print $"Plugin ($spec.name) is already installed and up-to-date!"
137 224 return
226 + print $"Downloading ($spec.name)..."
139 227 let archive_path = download-plugin $spec $cache_path
228 + print $"Unpacking ($spec.name)..."
140 229 let unpacked_path = unpack-plugin-archive $spec $archive_path
230 + print $"Installing ($spec.name)..."
141 231 let installed_plugin_path = install-plugin $spec $unpacked_path $plugins_path
143 232 print $"Plugin ($spec.name) installed into ($installed_plugin_path)!"