all repos — dotfiles @ ef4e054f609a65e639255b16addda1c1ad656ec4

my *nix dotfiles

nix/bin/xurls.nix (view raw)

 1{ pkgs, ... }:
 2
 3let
 4  name = "xurls";
 5  fzy = "${pkgs.fzy}/bin/fzy";
 6in
 7pkgs.writeShellScriptBin name
 8  ''
 9    content="$(tmux capture-pane -J -p)"
10
11    mapfile -t urls < <(echo "$content" | grep -oE '(https?|ftp|file):/?//[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]')
12    mapfile -t wwws < <(echo "$content" | grep -oE '(http?s://)?www\.[a-zA-Z](-?[a-zA-Z0-9])+\.[a-zA-Z]{2,}(/\S+)*' | grep -vE '^https?://' |sed 's/^\(.*\)$/http:\/\/\1/')
13    mapfile -t ips  < <(echo "$content" | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(:[0-9]{1,5})?(/\S+)*' |sed 's/^\(.*\)$/http:\/\/\1/')
14    mapfile -t gits < <(echo "$content" | grep -oE '(ssh://)?git@\S*' | sed 's/:/\//g' | sed 's/^\(ssh\/\/\/\)\{0,1\}git@\(.*\)$/https:\/\/\2/')
15    
16    items="$(printf '%s\n' "''${urls[@]}" "''${wwws[@]}" "''${ips[@]}" "''${gits[@]}" |
17        grep -v '^$' |
18        sort -u |
19        nl -w3 -s ' '
20    )"
21
22    [ -z "$items" ] && exit
23
24    u="$(${fzy} <<< "$items" | awk '{ print $2 }')"
25    $BROWSER "$u"
26  ''
27