github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/integrations/ssh_posix.mx (about) 1 private getHostsFile { 2 # Parse the hosts file and return uniq host names and IPs 3 4 cast: str 5 6 cat /etc/hosts -> !regexp: 'm/^(#.*|\s*)$/' -> regexp: "s/[\s\t]+/\n/" -> sort -> uniq 7 8 if { g ~/.ssh/config -> f +d } then { 9 cat ~/.ssh/config -> regexp 'f/Host\s([-.a-zA-Z0-9]+)/' 10 } 11 } 12 13 test unit private getHostsFile { 14 "StdoutRegex": "[-_.0-9a-zA-Z]+\n", 15 "StdoutType": "str", 16 "StdoutGreaterThan": 1, 17 "StdoutIsArray": true 18 } 19 20 private getHostsPrefixUser { 21 # prefixes getHostFile entries with $1 if that matches a `user@` pattern 22 23 cast str 24 25 if { $1 =~ '^[-_.a-zA-Z0-9]+@' } then { 26 $1 -> regexp 'f/(^[-_.a-zA-Z0-9]+@)' -> set prefix 27 getHostsFile -> prefix $prefix 28 } else { 29 getHostsFile 30 } 31 } 32 33 autocomplete set ssh %[ 34 { 35 Dynamic: '{ getHostsPrefixUser $PREFIX }' 36 IncManPage: true 37 AllowAny: true 38 FlagValues: { 39 "-i": [{ 40 IncFiles: true 41 }] 42 } 43 }, 44 { 45 Goto: "/0" 46 } 47 ] 48 49 autocomplete set ping %[ { 50 Dynamic: '{ getHostsFile }' 51 IncManPage: true 52 }] 53 54 autocomplete set rsync %[ 55 { 56 DynamicDesc: '{ 57 rsync --help -> @[^Options$..--help]re -> tabulate: --map --split-comma --column-wraps --key-inc-hint 58 }' 59 AllowMultiple: true 60 Optional: true 61 IncManPage: true 62 } 63 { 64 Dynamic: '{ getHostsFile }' 65 IncManPage: true 66 AllowMultiple: true 67 } 68 ] 69 70 autocomplete set sftp %[ { 71 Dynamic: '{ getHostsFile }' 72 IncManPage: true 73 }]