ソースを参照

Move 'uba' to saturnin as new command: xuris

Alois Mahdal 9 年 前
コミット
00d8bca55f
共有2 個のファイルを変更した117 個の追加0 個の削除を含む
  1. 1
    0
      mkit.ini
  2. 116
    0
      src/libexec/saturnin-xuris

+ 1
- 0
mkit.ini ファイルの表示

@@ -55,6 +55,7 @@
55 55
     src/libexec/saturnin-ln                 = saturnin-ln
56 56
     src/libexec/saturnin-menu               = saturnin-menu
57 57
     src/libexec/saturnin-uris               = saturnin-uris
58
+    src/libexec/saturnin-xuris              = saturnin-xuris
58 59
 
59 60
 [files:share]
60 61
     src/ffoo/saturnin_meta.sh               = ffoo/saturnin_meta.sh

+ 116
- 0
src/libexec/saturnin-xuris ファイルの表示

@@ -0,0 +1,116 @@
1
+#!/bin/bash
2
+
3
+# launch Uzbl once per each URI in stdin
4
+
5
+. $(ffoom path) || exit 3
6
+ffoo import pretty
7
+
8
+SATURNIN_XURIS_NOTIFICATIONS=true
9
+SATURNIN_XURIS_LIMIT=100
10
+SATURNIN_XURIS_ALWAYS_RUN=false
11
+SATURNIN_XURIS_UNIQ=true
12
+SATURNIN_XURIS_CHOICE="${SATURNIN_XURIS_CHOICE:-false}"
13
+
14
+FFOO_DEBUG=true
15
+
16
+usage() {
17
+    mkusage "[-u|--uniq] [-a|--always-run] [-l|--limit N] [-c|--choose] [-C|--choice-cmd COMMAND]"
18
+}
19
+
20
+get_i3_wsname() {
21
+    #
22
+    # Get current workspace name
23
+    #
24
+    i3-msg -t get_workspaces \
25
+      | jq '.[] | {focused, name}' \
26
+      | grep -F -A 1 'focused": true' \
27
+      | grep name \
28
+      | cut -d\" -f4
29
+}
30
+
31
+enum_bins() {
32
+    echo uzbl-browser
33
+    echo vimb
34
+    echo firefox
35
+    echo opera-rh
36
+    echo opera-beta
37
+    echo opera
38
+    echo wget
39
+}
40
+
41
+decide_bin() {
42
+    #
43
+    # Decide what browser to use
44
+    #
45
+    local context="$(hostname -s)/$(get_i3_wsname)"
46
+    debug -v context
47
+    case "$context" in
48
+        hugo/*)         echo vimb ;;
49
+        fullmoon/*)     echo uzbl-browser ;;
50
+        *)              echo uzbl-browser ;;
51
+    esac
52
+}
53
+
54
+maybe_uniq() {
55
+    $SATURNIN_XURIS_UNIQ || { cat; return; }
56
+    sort | uniq
57
+}
58
+
59
+notify() {
60
+    $SATURNIN_XURIS_NOTIFICATIONS || return 0
61
+    local summary="saturnin-xuris"
62
+    local body="$1"
63
+    notify-send -a saturnin-xuris "$summary" "$body"
64
+}
65
+
66
+open_from() {
67
+    local list="$1"
68
+    local count=$(wc -l <$list)
69
+
70
+    test $count -gt $SATURNIN_XURIS_LIMIT && {
71
+        notify "too much URIs; giving up: $count > $SATURNIN_XURIS_LIMIT"
72
+        return 1
73
+    }
74
+
75
+    test $count -eq 0 && {
76
+        $SATURNIN_XURIS_ALWAYS_RUN && $SATURNIN_XURIS_BIN &
77
+        return 0
78
+    }
79
+
80
+    cat $list \
81
+      | while read uri;
82
+        do
83
+            $SATURNIN_XURIS_BIN "$uri" &
84
+        done
85
+}
86
+
87
+while true; do case $1 in
88
+    -a|--always-run) SATURNIN_XURIS_ALWAYS_RUN=true; shift ;;
89
+    -b|--bin)        SATURNIN_XURIS_BIN="$2"; shift; shift ;;
90
+    -c|--choose)     SATURNIN_XURIS_CHOICE="enum_bins | saturnin dmenu"; shift ;;
91
+    -C|--choice-cmd) SATURNIN_XURIS_CHOICE="$2"; shift; shift ;;
92
+    -l|--limit)      SATURNIN_XURIS_LIMIT=$2; shift; shift ;;
93
+    -u|--uniq)       SATURNIN_XURIS_UNIQ=true;       shift ;;
94
+    -U|--no-uniq)    SATURNIN_XURIS_UNIQ=false;      shift ;;
95
+    -*)       usage ;;
96
+    "")       break ;;
97
+    *)        usage ;;
98
+esac done
99
+
100
+debug -v SATURNIN_XURIS_ALWAYS_RUN \
101
+         SATURNIN_XURIS_CHOICE \
102
+         SATURNIN_XURIS_LIMIT \
103
+         SATURNIN_XURIS_UNIQ
104
+
105
+SATURNIN_XURIS_URI_LIST=$(mktemp -t saturnin-xuris.XXXXXXXX)
106
+cat | maybe_uniq | grep . >$SATURNIN_XURIS_URI_LIST
107
+
108
+# choice of URI has been made; we may try to use dmenu
109
+bash -n <<<"$SATURNIN_XURIS_CHOICE"
110
+SATURNIN_XURIS_BIN=$(eval "$SATURNIN_XURIS_CHOICE")
111
+SATURNIN_XURIS_BIN="${SATURNIN_XURIS_BIN:-$(decide_bin)}"
112
+
113
+debug -v SATURNIN_XURIS_BIN
114
+
115
+open_from $SATURNIN_XURIS_URI_LIST
116
+rm $SATURNIN_XURIS_URI_LIST