aboutsummaryrefslogtreecommitdiffstats
path: root/xwindowURI
blob: 6e9235af99410feb14986955c5979b3415987ee2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh
if [ ! "$1" ];then
  id="$(xwinID)"
else
  id="$1"
fi

class=$(xclass -id "$id")
#echo "$class"

case "$class" in
mupdf)
  basename="$(xwintitle "$id" | rev | cut '-d ' -f5- | rev)"
  echo "b: $basename"
  page="$(xwintitle "$id" | tr ' ' '\n' | grep '[0-9][0-9]*/[0-9][0-9]*' | cut -d/ -f1)"
  echo "$page"
  for PID in $(pgrep mupdf);do
    argv1="$(cat /proc/$PID/cmdline | tr '\0' '\n' | sed -n 2p)"
    cd "$(readlink /proc/$PID/cwd)"
    abspath="$(normalpath "$argv1")"
    echo "a: $abspath"
    echo "b: $basename"
    if [ "$(basename "$abspath")" = "$basename" ];then
      printf "file://%s#page=%s\n" "$(uriescape "$abspath")" "$page"
      exit 0
    fi
  done
  ;;
Navigator)
  xwintitle "$id" | rev | cut '-d ' -f4 | rev
  ;;
*)
  echo "class: $class"
  ;;
esac