repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

Merge branch 'trunk' of github.com:bugabinga/dotfiles into trunk

2f34f51c0a070371f30d31939887154c9f00ec46

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

+100 / −11 text lines

Diff layout

neovim/puk.nu

Modified

+100 / −11 text lines

11#!/usr/bin/env nu
33# TODO:
4# treesj for nushell
5# setup new nvim-treesitter and nvim-treesitter-textobjects
6# clean unspecified plugins
74# XXX use rss feeds of forges to find latest commit
96# an out-of-band plugin manager for neovim.
1714 let cache_path = nvim --headless --clean +'lua print(vim.fn.stdpath "cache")' +q | complete | get stderr
1815 let plugins_path = [ $data_path site pack puk opt ] | path join
1916 let plugin_specs = open puk.plugins.nuon
17 print 'Installing plugins from puk.plugins.nuon.'
2018 $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.'
2122 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.
27def '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 }
50}
52# deletes all existing plugins, that are NOT in the specs!
53def 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 }
65}
2467# given a plugin spec, and a plugins base install directory, this method generates
2568# a new path, that points to the location the plugin should be installed into.
2669def make-plugin-path [
4891 return false
4992 }
5093 let commit = open --raw $commit_file_path | str trim
51 $commit == $spec.commit
94 return ($commit == $spec.commit)
95}
97def 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
112 }
113 }
114 }
115 }
116 $commit
117}
119def 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
131 }
132 }
133 }
134 }
135 $spec | format pattern $url_format
54138def generate-download-url [
76160] {
77161 let archive_path = [ $cache_path ($spec.name + '.tar.gz') ] | path join
78162 if ($archive_path | path exists) {
163 print $"($spec.name) already cached in ($archive_path)"
79164 return $archive_path
80165 }
81166 let url = generate-download-url $spec
99184 $tmp_path
187let 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' } },
192}
193let allowed_filetypes = [ lua vim scm txt $allowed_shared_lib_type ]
102195def install-plugin [
103196 spec: record # a plugin to install
104197 folder_path: path # unpacked path to plugin folder
108201 try { rm --trash --recursive $plugin_path }
109202 mkdir $plugin_path
110203 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 ]
117204 let exclusions = [**/tests/**, **/scripts/**, **/fixtures/**, **/target/release/deps/**]
118205 glob $"**/*.{($allowed_filetypes | str join ',')}" --exclude $exclusions |
119206 path relative-to (pwd) |
136223 print $"Plugin ($spec.name) is already installed and up-to-date!"
137224 return
138225 }
226 print $"Downloading ($spec.name)..."
139227 let archive_path = download-plugin $spec $cache_path
228 print $"Unpacking ($spec.name)..."
140229 let unpacked_path = unpack-plugin-archive $spec $archive_path
230 print $"Installing ($spec.name)..."
141231 let installed_plugin_path = install-plugin $spec $unpacked_path $plugins_path
143232 print $"Plugin ($spec.name) installed into ($installed_plugin_path)!"