Detect rokulog files even when .txt extension exists
dblume

dblume commited on 2024-12-01 20:13:54
Showing 2 changed files, with 25 additions and 0 deletions.

... ...
@@ -447,4 +447,19 @@ lua << EOF
447 447
   --    skip_input_prompt = true,
448 448
   --    cscope = { skip_picker_for_single_result = true },
449 449
   })
450
+
451
+  -- From https://www.reddit.com/r/neovim/comments/wcq6sp/override_file_type_detection_for_existing/
452
+  vim.filetype.add {
453
+  pattern = {
454
+    ['.*'] = {
455
+      priority = -math.huge,
456
+      function(path, bufnr)
457
+        local content = vim.filetype.getlines(bufnr, 1)
458
+        if vim.filetype.matchregex(content, [[^\d\{2\}-\d\{2\} \d\{2\}:\d\{2\}:\d\{2\}.\d\{3\}\s\+\(n\|dev\|\d\+\|tvinput\.\S\+\) \[]]) then
459
+          return 'rokulog'
460
+        end
461
+      end,
462
+    },
463
+  },
464
+}
450 465
 EOF
... ...
@@ -0,0 +1,10 @@
1
+" For vim put this in ~/.vim/scripts.vim.
2
+" For neovim: See ~/.config/nvim/init.vim
3
+" See https://www.reddit.com/r/neovim/comments/wcq6sp/override_file_type_detection_for_existing/
4
+if did_filetype()  " filetype already set..
5
+  finish           " ..don't do these checks
6
+endif
7
+" Close, didn't bother making it match publishing channels like 12_a42f:
8
+if getline(1) =~? '^\d\{2\}-\d\{2\} \d\{2\}:\d\{2\}:\d\{2\}.\d\{3\}\s\+\(n\|dev\|\d\+\|tvinput\.\S\+\) \['
9
+  setfiletype rokulog
10
+endif
0 11