Skip to content

Commit 18b5d13

Browse files
committed
Improve the sub shell function and allow passing a pattern as argument
1 parent 70e33e1 commit 18b5d13

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ If you work with many chains, the following function can be added to your `.bash
2929

3030
You need to have [fzf](https://github.com/junegunn/fzf) installed and `subrpc` v0.0.4+ installed.
3131

32-
function subopen() {
32+
# A function to interactively open a chain in your Browser
33+
# Simply call `sub` or `sub <pattern>`
34+
function sub() {
3335
chains=$(subrpc reg chains)
34-
chain=$(echo $chains | sort -r | fzf -1 --prompt="Select the chain to open in your browser > ")
35-
subrpc endpoints open $chain
36+
37+
if [ ! -z "$1" ]; then
38+
query="$1"
39+
echo "Searching for chains matching: $query"
40+
chain=$(echo "$chains" | sort -r | fzf -1 -q "$query" --prompt="Select the chain to open in your browser > ")
41+
else
42+
chain=$(echo "$chains" | sort -r | fzf -1 --prompt="Select the chain to open in your browser > ")
43+
fi
44+
subrpc endpoints open "$chain"
3645
}
3746

3847
Call the function invoking simply `subopen`. Type the name of a chain, it can be approximate, for instance `river`, then press enter.

cli/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ If you work with many chains, the following function can be added to your `.bash
2929

3030
You need to have [fzf](https://github.com/junegunn/fzf) installed and `subrpc` v0.0.4+ installed.
3131

32-
function subopen() {
32+
# A function to interactively open a chain in your Browser
33+
# Simply call `sub` or `sub <pattern>`
34+
function sub() {
3335
chains=$(subrpc reg chains)
34-
chain=$(echo $chains | sort -r | fzf -1 --prompt="Select the chain to open in your browser > ")
35-
subrpc endpoints open $chain
36+
37+
if [ ! -z "$1" ]; then
38+
query="$1"
39+
echo "Searching for chains matching: $query"
40+
chain=$(echo "$chains" | sort -r | fzf -1 -q "$query" --prompt="Select the chain to open in your browser > ")
41+
else
42+
chain=$(echo "$chains" | sort -r | fzf -1 --prompt="Select the chain to open in your browser > ")
43+
fi
44+
subrpc endpoints open "$chain"
3645
}
3746

3847
Call the function invoking simply `subopen`. Type the name of a chain, it can be approximate, for instance `river`, then press enter.

doc/subopen.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
#!/usr/bin/env bash
22

3-
function subopen() {
3+
# A function to interactively open a chain in your Browser
4+
# Simply call `sub` or `sub <pattern>`
5+
function sub() {
46
chains=$(subrpc reg chains)
5-
chain=$(echo $chains | sort -r | fzf -1 --prompt="Select the chain to open in your browser > ")
6-
subrpc endpoints open $chain
7+
8+
if [ ! -z "$1" ]; then
9+
query="$1"
10+
echo "Searching for chains matching: $query"
11+
chain=$(echo "$chains" | sort -r | fzf -1 -q "$query" --prompt="Select the chain to open in your browser > ")
12+
else
13+
chain=$(echo "$chains" | sort -r | fzf -1 --prompt="Select the chain to open in your browser > ")
14+
fi
15+
subrpc endpoints open "$chain"
716
}

0 commit comments

Comments
 (0)