summaryrefslogtreecommitdiff
path: root/rc
diff options
context:
space:
mode:
authorMathieu Ablasou <alexherbo2@gmail.com>2020-11-25 02:08:01 +0100
committerMathieu Ablasou <alexherbo2@gmail.com>2020-11-25 05:06:07 +0100
commit194b08cdcc238d1d926a20e0b789f1089450dbd5 (patch)
tree64fb7d04ef3635f6dab7ebc252280d047c728588 /rc
parent29a841cc9f1341be386f7a8228ae73953406ef6b (diff)
Add an :edit-search command
Diffstat (limited to 'rc')
-rwxr-xr-xrc/connect/commands/:edit-search25
-rwxr-xr-xrc/connect/modules/dmenu/commands/:dmenu-grep11
-rwxr-xr-xrc/connect/modules/fzf/commands/:fzf-grep11
-rwxr-xr-xrc/connect/modules/fzy/commands/:fzy-grep11
-rwxr-xr-xrc/connect/modules/rofi/commands/:rofi-grep11
-rwxr-xr-xrc/connect/modules/wofi/commands/:wofi-grep11
6 files changed, 35 insertions, 45 deletions
diff --git a/rc/connect/commands/:edit-search b/rc/connect/commands/:edit-search
new file mode 100755
index 0000000..903bd79
--- /dev/null
+++ b/rc/connect/commands/:edit-search
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# Open files from search result.
+#
+# Input format: <file>:<line>:<column>:<text>
+
+# Execute the following Kakoune commands.
+#
+# Input: <file>:<line>:<column>:<text>
+# Output: <file>␤<line>␤<column>
+select_each_line='<a-s>_'
+select_search_fields='s^(.+):(\d+):(\d+):(.+)$<ret>'
+save_selections='Z'
+select_file_save_and_restore='1s<ret>"fZz'
+select_line_save_and_restore='2s<ret>"f<a-Z>az'
+select_column_save_and_restore='3s<ret>"f<a-Z>az'
+select_data='"fz'
+prepare_output='y%<a-R>a<ret><esc>'
+delete_end_of_file='ged'
+
+kak -f "${select_each_line}${select_search_fields}${save_selections}${select_file_save_and_restore}${select_line_save_and_restore}${select_column_save_and_restore}${select_data}${prepare_output}${delete_end_of_file}" |
+
+while read file; read line; read column; do
+ :edit "$file" "+$line:$column"
+done
diff --git a/rc/connect/modules/dmenu/commands/:dmenu-grep b/rc/connect/modules/dmenu/commands/:dmenu-grep
index cb02ed4..d6634ba 100755
--- a/rc/connect/modules/dmenu/commands/:dmenu-grep
+++ b/rc/connect/modules/dmenu/commands/:dmenu-grep
@@ -6,13 +6,6 @@
# Dependencies:
# – ripgrep (https://github.com/BurntSushi/ripgrep)
-rg --line-number --with-filename '.+' "$@" |
+rg --column --with-filename '.+' "$@" |
dmenu -l 20 -i -p 'Open files (search by content)' |
-
-while read line; do
- # Output format: <file>:<line>:<text>
- file=${line%%:*}
- line_number=${line#*:}; line_number=${line_number%%:*}
-
- :edit "$file" "+$line_number"
-done
+:edit-search
diff --git a/rc/connect/modules/fzf/commands/:fzf-grep b/rc/connect/modules/fzf/commands/:fzf-grep
index 41b1f89..8a1d52b 100755
--- a/rc/connect/modules/fzf/commands/:fzf-grep
+++ b/rc/connect/modules/fzf/commands/:fzf-grep
@@ -6,13 +6,6 @@
# Dependencies:
# – ripgrep (https://github.com/BurntSushi/ripgrep)
-rg --line-number --with-filename '.+' "$@" |
+rg --column --with-filename '.+' "$@" |
fzf --prompt='(g)>' |
-
-while read line; do
- # Output format: <file>:<line>:<text>
- file=${line%%:*}
- line_number=${line#*:}; line_number=${line_number%%:*}
-
- :edit "$file" "+$line_number"
-done
+:edit-search
diff --git a/rc/connect/modules/fzy/commands/:fzy-grep b/rc/connect/modules/fzy/commands/:fzy-grep
index 788a774..e6d17d4 100755
--- a/rc/connect/modules/fzy/commands/:fzy-grep
+++ b/rc/connect/modules/fzy/commands/:fzy-grep
@@ -6,13 +6,6 @@
# Dependencies:
# – ripgrep (https://github.com/BurntSushi/ripgrep)
-rg --line-number --with-filename '.+' "$@" |
+rg --column --with-filename '.+' "$@" |
fzy --prompt='(g)>' |
-
-while read line; do
- # Output format: <file>:<line>:<text>
- file=${line%%:*}
- line_number=${line#*:}; line_number=${line_number%%:*}
-
- :edit "$file" "+$line_number"
-done
+:edit-search
diff --git a/rc/connect/modules/rofi/commands/:rofi-grep b/rc/connect/modules/rofi/commands/:rofi-grep
index f0215a2..c4adb7b 100755
--- a/rc/connect/modules/rofi/commands/:rofi-grep
+++ b/rc/connect/modules/rofi/commands/:rofi-grep
@@ -6,13 +6,6 @@
# Dependencies:
# – ripgrep (https://github.com/BurntSushi/ripgrep)
-rg --line-number --with-filename '.+' "$@" |
+rg --column --with-filename '.+' "$@" |
rofi -dmenu -i -p 'Open files (search by content)' |
-
-while read line; do
- # Output format: <file>:<line>:<text>
- file=${line%%:*}
- line_number=${line#*:}; line_number=${line_number%%:*}
-
- :edit "$file" "+$line_number"
-done
+:edit-search
diff --git a/rc/connect/modules/wofi/commands/:wofi-grep b/rc/connect/modules/wofi/commands/:wofi-grep
index a8c80fe..e5ccc3b 100755
--- a/rc/connect/modules/wofi/commands/:wofi-grep
+++ b/rc/connect/modules/wofi/commands/:wofi-grep
@@ -6,13 +6,6 @@
# Dependencies:
# – ripgrep (https://github.com/BurntSushi/ripgrep)
-rg --line-number --with-filename '.+' "$@" |
+rg --column --with-filename '.+' "$@" |
wofi --dmenu --prompt 'Open files (search by content)' |
-
-while read line; do
- # Output format: <file>:<line>:<text>
- file=${line%%:*}
- line_number=${line#*:}; line_number=${line_number%%:*}
-
- :edit "$file" "+$line_number"
-done
+:edit-search