Skip to content

Commit

Permalink
feat(nvim)!: split personal and work Corpus directories
Browse files Browse the repository at this point in the history
As noted in the comments here I want:

1. Work notes stored in a local-only Git repo, with document files
   synced to Google Drive (but not Git metadata).
2. Personal notes stored in a normal local-only Git repo, but not synced
   to Google Drive.

To achieve this, going to use the `--separate-git-dir` option to
`git-init`, which will create a `.git` file in the work notes directory
containing a "Git link"; ie. a plain-text file containing the path to
the Git directory for the repo:

    gitdir: /absolute/path/to/Corpus.git

BREAKING CHANGES:

I moved the host-specific override block to _after_ plug-ins are loaded,
because only then can I meaningfully set up the Corpus directories.

If I ever need to do overrides before plug-ins get loaded, I'll have to
do something similar to what I am doing in my SSH config, where I have
"pre" and "post" includes.
  • Loading branch information
wincent committed Jul 8, 2024
1 parent efc2adc commit aee6574
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 37 deletions.
32 changes: 32 additions & 0 deletions aspects/nvim/files/.config/nvim/host/comp-ktw7q4c5jh.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- Host-specific overrides for comp-ktw7q4c5jh.
local has_corpus, corpus = pcall(require, 'wincent.corpus')
if has_corpus then
corpus({
bang_creation = true,
directories = {
['~/Documents/Corporate/Corpus'] = {
autocommit = true,
autoreference = 1,
autotitle = 1,
base = './',
transform = 'local',
},
['~/Documents/Personal/Corpus'] = {
autocommit = true,
autoreference = 1,
autotitle = 1,
base = './',
transform = 'local',
},
['~/code/masochist/content/content/wiki'] = {
autocommit = false,
autoreference = 1,
autotitle = 1,
base = '/wiki/',
tags = { 'wiki' },
transform = 'web',
},
},
sort = 'stat',
})
end
24 changes: 24 additions & 0 deletions aspects/nvim/files/.config/nvim/host/latina.lua
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
-- Host-specific overrides for "latina".
local has_corpus, corpus = pcall(require, 'wincent.corpus')
if has_corpus then
corpus({
bang_creation = true,
directories = {
['~/Documents/Corpus'] = {
autocommit = true,
autoreference = 1,
autotitle = 1,
base = './',
transform = 'local',
},
['~/code/masochist/content/content/wiki'] = {
autocommit = false,
autoreference = 1,
autotitle = 1,
base = '/wiki/',
tags = { 'wiki' },
transform = 'web',
},
},
sort = 'stat',
})
end
49 changes: 12 additions & 37 deletions aspects/nvim/files/.config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,6 @@ vim.api.nvim_set_keymap('n', '<Leader>f', '<Plug>(FerretAckWord)', {})
-- use <Leader>s (mnemonic: "[s]ubstitute") instead.
vim.api.nvim_set_keymap('n', '<Leader>s', '<Plug>(FerretAcks)', {})

-- Allow for per-machine overrides.
local hostname = vim.fn.substitute(vim.fn.hostname(), '\\..*', '', '')
local overrides = {
config .. '/host/' .. hostname .. '.vim',
config .. '/host/' .. hostname .. '.lua',
config .. '/init-local.vim',
config .. '/init-local.lua',
}
for _, override in ipairs(overrides) do
if vim.fn.filereadable(override) == 1 then
vim.cmd('source ' .. override)
end
end

-------------------------------------------------------------------------------
-- Plugins {{{1 ---------------------------------------------------------------
-------------------------------------------------------------------------------
Expand Down Expand Up @@ -463,29 +449,18 @@ if has_commandt then
})
end

local has_corpus, corpus = pcall(require, 'wincent.corpus')
if has_corpus then
corpus({
bang_creation = true,
directories = {
['~/Documents/Corpus'] = {
autocommit = true,
autoreference = 1,
autotitle = 1,
base = './',
transform = 'local',
},
['~/code/masochist/content/content/wiki'] = {
autocommit = false,
autoreference = 1,
autotitle = 1,
base = '/wiki/',
tags = { 'wiki' },
transform = 'web',
},
},
sort = 'stat',
})
-- Allow for per-machine overrides.
local hostname = string.lower(vim.fn.substitute(vim.fn.hostname(), '\\..*', '', ''))
local overrides = {
config .. '/host/' .. hostname .. '.vim',
config .. '/host/' .. hostname .. '.lua',
config .. '/init-local.vim',
config .. '/init-local.lua',
}
for _, override in ipairs(overrides) do
if vim.fn.filereadable(override) == 1 then
vim.cmd('source ' .. override)
end
end

-------------------------------------------------------------------------------
Expand Down
50 changes: 50 additions & 0 deletions aspects/nvim/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,56 @@ task('install gems', async () => {
});
});

// On my work machine, I divide my Corpus notes into two folders: one is
// work-specific, synced via Google Drive, and the other has personal notes
// in it and is not synced. Because Google Drive isn't good at handling Git
// directories, I store that elsewhere, and it doesn't get synced.
task('create Corpus directories', when('wincent', 'work'), async () => {
// Corporate Corpus files go here.
await file({path: '~/Documents/Corporate', state: 'directory'});
await file({path: '~/Documents/Corporate/Corpus', state: 'directory'});

// Git directory goes under `~/Library/Application Support/Corpus`, with
// subdirectories of the form "$HOME-relative path to Corpus files" and a
// `.git` extension.
await file({
path: '~/Library/Application Support/Corpus',
state: 'directory',
});
await file({
path: '~/Library/Application Support/Corpus/Documents',
state: 'directory',
});
await file({
path: '~/Library/Application Support/Corpus/Documents/Corporate',
state: 'directory',
});
await file({
path: '~/Library/Application Support/Corpus/Documents/Corporate/Corpus.git',
state: 'directory',
});

await command('git', [
'init',
`--separate-git-dir=${
path.home.join(
'Library/Application Support/Corpus/Documents/Corporate/Corpus.git',
)
}`,
], {
chdir: '~/Documents/Corporate/Corpus',
creates: '~/Documents/Corporate/Corpus/.git',
});

await file({path: '~/Documents/Personal', state: 'directory'});
await file({path: '~/Documents/Personal/Corpus', state: 'directory'});

await command('git', ['init'], {
chdir: '~/Documents/Personal/Corpus',
creates: '~/Documents/Personal/Corpus/.git',
});
});

// added in 1a9f9b9fd and probably not used since...
// pip2 install vim-vint

Expand Down
2 changes: 2 additions & 0 deletions helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ function checkCondition(label: string): boolean {
return variable('profile') === 'personal';
case 'wincent':
return variable('identity') === 'wincent';
case 'work':
return variable('profile') === 'work';
default:
throw new Error(
`checkCondition(): Unknown condition label ${JSON.stringify(label)}`,
Expand Down

0 comments on commit aee6574

Please sign in to comment.