Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace uses of eawk with re:awk #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion comp.org
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ edit:completion:arg-completer[brew] = (comp:subcommands &opts= [ version ] $brew
*Tip:* note that the values of =&opts= are functions (e.g. ={ vagrant-up -h | comp:extract-opts }=) instead of arrays (e.g. =( vagrant up -h | comp:extract-opts )=). As mentioned in Example #5, both would be valid, but in the latter case they are all initialized at load time (when the data structure is defined), which might introduce a delay (particularly with more command definitions). By using functions the options are only extracted at runtime when the completion is requested. For further optimization, =vagrant-opts= could be made to memoize the values so that the delay only occurs the first time.

#+begin_src elvish
use re

vagrant-completions = [
&up= (comp:sequence [] \
&opts= { vagrant up -h | comp:extract-opts }
Expand All @@ -181,7 +183,7 @@ vagrant-completions = [
&add= (comp:sequence [] \
&opts= { vagrant box add -h | comp:extract-opts }
)
&remove= (comp:sequence [ { vagrant box list | eawk [_ @f]{ put $f[0] } } ... ] \
&remove= (comp:sequence [ { vagrant box list | re:awk [_ @f]{ put $f[0] } } ... ] \
&opts= { vagrant box remove -h | comp:extract-opts }
)
])]
Expand Down
3 changes: 2 additions & 1 deletion evemu.elv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ./comp
use re
use str

var -complete-dev = {
Expand All @@ -16,7 +17,7 @@ var ev-code-header = /usr/include/linux/input-event-codes.h

fn -defs-with-prefix {|prefix|
grep "#define "$prefix"_" $ev-code-header |
eawk {|line @fields| put $fields[1] }
re:awk {|line @fields| put $fields[1] }
}

fn -ev-codes-for-type {|type|
Expand Down
3 changes: 2 additions & 1 deletion evemu.org
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ All of these commands operate on evdev nodes, contained in =/dev/input/=. Each r

#+begin_src elvish
use ./comp
use re
use str

var -complete-dev = {
Expand All @@ -36,7 +37,7 @@ Some commands take axis or key constants defined in the Kernel's =input-event-co

fn -defs-with-prefix {|prefix|
grep "#define "$prefix"_" $ev-code-header |
eawk {|line @fields| put $fields[1] }
re:awk {|line @fields| put $fields[1] }
}
#+end_src

Expand Down
2 changes: 1 addition & 1 deletion git.elv
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var git-completions = [

fn init {
set completions = [&]
-run-git help -a --no-verbose | eawk {|line @f| if (re:match '^ [a-z]' $line) { put $@f } } | each {|c|
-run-git help -a --no-verbose | re:awk {|line @f| if (re:match '^ [a-z]' $line) { put $@f } } | each {|c|
var seq = [ $comp:files~ ... ]
if (has-key $git-completions $c) {
set seq = $git-completions[$c]
Expand Down
4 changes: 2 additions & 2 deletions git.org
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ In the =git:init= function we initialize the =$completions= map with the necessa
#+begin_src elvish :noweb yes
fn init {
set completions = [&]
-run-git help -a --no-verbose | eawk {|line @f| if (re:match '^ [a-z]' $line) { put $@f } } | each {|c|
-run-git help -a --no-verbose | re:awk {|line @f| if (re:match '^ [a-z]' $line) { put $@f } } | each {|c|
var seq = [ $comp:files~ ... ]
if (has-key $git-completions $c) {
set seq = $git-completions[$c]
Expand Down Expand Up @@ -247,7 +247,7 @@ In the =git:init= function we initialize the =$completions= map with the necessa
Next , we fetch the list of valid git commands from the output of =git help -a=, and store the corresponding completion sequences in =$completions=. All of them are configured to produce completions for their options, as extracted by the =-git-opts= function. Commands that have corresponding definitions in =$git-completions= get them, otherwise they get the generic filename completer.

#+begin_src elvish :noweb-ref init-git-commands :tangle no
-run-git help -a --no-verbose | eawk [line @f]{ if (re:match '^ [a-z]' $line) { put $@f } } | each [c]{
-run-git help -a --no-verbose | re:awk [line @f]{ if (re:match '^ [a-z]' $line) { put $@f } } | each [c]{
seq = [ $comp:files~ ... ]
if (has-key $git-completions $c) {
seq = $git-completions[$c]
Expand Down
4 changes: 2 additions & 2 deletions ssh.elv
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var config-files = [ ~/.ssh/config /etc/ssh/ssh_config /etc/ssh_config ]
fn -ssh-hosts {
var hosts = [&]
all $config-files | each {|file|
set _ = ?(cat $file 2>&-) | eawk {|_ @f|
set _ = ?(cat $file 2>&-) | re:awk {|_ @f|
if (re:match '^(?i)host$' $f[0]) {
all $f[1..] | each {|p|
if (not (re:match '[*?!]' $p)) {
Expand All @@ -21,7 +21,7 @@ fn -gen-ssh-options {
if (eq $-ssh-options []) {
set -ssh-options = [(
set _ = ?(cat (man -w ssh_config 2>&-)) |
eawk {|l @f| if (re:match '^\.It Cm' $l) { put $f[2] } } |
re:awk {|l @f| if (re:match '^\.It Cm' $l) { put $f[2] } } |
comp:decorate &suffix='='
)]
}
Expand Down
4 changes: 2 additions & 2 deletions ssh.org
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The =-ssh-hosts= function extracts all hostnames from the files listed in =$conf
fn -ssh-hosts {
var hosts = [&]
all $config-files | each {|file|
set _ = ?(cat $file 2>&-) | eawk {|_ @f|
set _ = ?(cat $file 2>&-) | re:awk {|_ @f|
if (re:match '^(?i)host$' $f[0]) {
all $f[1..] | each {|p|
if (not (re:match '[*?!]' $p)) {
Expand All @@ -101,7 +101,7 @@ We store in =-ssh-options= all the possible configuration options, by parsing th
if (eq $-ssh-options []) {
set -ssh-options = [(
set _ = ?(cat (man -w ssh_config 2>&-)) |
eawk {|l @f| if (re:match '^\.It Cm' $l) { put $f[2] } } |
re:awk {|l @f| if (re:match '^\.It Cm' $l) { put $f[2] } } |
comp:decorate &suffix='='
)]
}
Expand Down