aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2025-10-13 15:25:24 +0530
committerAkshay Nair <phenax5@gmail.com>2025-10-21 13:39:45 +0530
commit351d55648ea26335b713140bfc0c4f69e2d70489 (patch)
treeb43cc6559aec53278a032ebb99657ac537b8fcba /scripts
parent38dc33178ed1ec08277782dba40c4fa55c07287c (diff)
downloadkakoune-config-351d55648ea26335b713140bfc0c4f69e2d70489.tar.gz
kakoune-config-351d55648ea26335b713140bfc0c4f69e2d70489.zip
Add grep-write command
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/apply_vimgrep_updates.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/apply_vimgrep_updates.js b/scripts/apply_vimgrep_updates.js
new file mode 100755
index 0000000..9707aab
--- /dev/null
+++ b/scripts/apply_vimgrep_updates.js
@@ -0,0 +1,29 @@
+#!/usr/bin/env bun
+
+const main = async () => {
+ let count = 0
+ for await (const line of console) {
+ const [_, filepath, row, _col, text] = line.match(/(.*):(\d+):(\d+):(.*)/) ?? []
+ if (filepath) {
+ const isApplied = await apply_edit(filepath, Number(row), text);
+ if (isApplied) count++
+ }
+ }
+ return count
+}
+
+const apply_edit = async (filepath, row, text) => {
+ if (!Number.isFinite(row) || row <= 0) return false;
+ const file = Bun.file(filepath)
+ const lines = (await file.text()).split('\n')
+ if (lines.length > row) {
+ lines[row - 1] = text
+ await Bun.write(filepath, lines.join('\n'))
+ return true
+ }
+ return false
+}
+
+const changesCount = await main()
+console.log(`Applied ${changesCount} changes`)
+