User Tools

Site Tools


awesome

Awesome WM integration

You would think using awful.layout.suit.max is enough, but you can do other awesome things.

Using awful.prompt

The following is a fairly generic lua function that displays a prompt in the mypromptbox textbox (change it below to whatever you've called it), and sends the result back with uzblctrl. More details below

function uzbl_prompt(prompt, text, socket, command)
    if command then
        -- if a command prefix is provided
        command = command .. ' '
    else
        command = ""
    end

    awful.prompt.run({prompt=prompt, text=text},
        mypromptbox[mouse.screen],
        function(input)
            awful.util.spawn(string.format("uzblctrl -s '%s' -c '%s%s'", socket, command, input))
        end)
end

Parameters

  • prompt: Something like “uzbl: ”
  • text: Editable text that is already in the textbox, such as the current uri ($6). Could be an empty string.
  • socket: The full path to the current instance socket ($5)
  • command: A uzbl command that prefixes the user input

Examples:

bind o = sh 'echo \'uzbl_prompt(“uzbl uri: ”, “\'$6\'”, “\'$5\'”, “uri”)\' | awesome-client'

This replaces the “o” bind and uses the prompt awesome editing capabilities to allow you to edit the current uri.

Note the ugly backslashes everywhere, having to use sh sucks.

bind !js          = sh 'echo \'uzbl_prompt("uzbl js: ", "", "\'$5\'", "js")\' | awesome-client'

This does not include text field, but it is an empty string.

bind :            = sh 'echo \'uzbl_prompt("uzbl cmd: ", "", "\'$5\'")\' | awesome-client'

This does not include command field, but it is not an empty string. (FIXME: This is inconsistent and sucks)

Using awful.prompt for url completion

With this uzbl command binding

 @cbind q = sh 'printf '"'"'uzbl_prompt("uri: ", "", "%1s", "uri")\\\\\\\\n'"'"' "$4" | awesome-client'

and this awesome function, you can do tab-completion of URLs from your history

function uzbl_prompt(prompt, text, fifo, command)

  if command then
      -- if a command prefix is provided
      command = command .. ' '
  else
      command = ""
  end
  awful.prompt.run({prompt='uzbl '..prompt, text=text},
      mypromptbox[mouse.screen].widget,
      function(input)
          awful.util.spawn_with_shell(string.format("echo '%s%s' >%s", command, input, fifo))
      end,
      function(cmd, cur_pos, ncomp)
              -- get the url
              local urls = {}
              f = io.popen('awk \'{print $3}\' '.. os.getenv("HOME") ..  '/.local/share/uzbl/history | sort -u')
              for url in f:lines() do
                      table.insert(urls, url)
              end
              f:close()
              -- abort completion under certain circumstances
              if #cmd == 0 or (cur_pos ~= #cmd + 1 and cmd:sub(cur_pos, cur_pos) ~= " ") then
                      return cmd, cur_pos
              end
              -- match
              local matches = {}
              table.foreach(urls, function(x)
                      if urls[x]:find(cmd:sub(1,cur_pos)) then
                              table.insert(matches, urls[x])
                      end
              end)
              -- if there are no matches
              if #matches == 0 then
                      return
              end
              -- cycle
              while ncomp > #matches do
                      ncomp = ncomp - #matches
              end
              -- return match and position
              return matches[ncomp], cur_pos
      end)

end

Something like tabs

Simple script that displays list of all instances of uzbl in dmenu, then raises and focuses the chosen one. I believe it can be easily adapted for other WM. Is it possible to replace awesome lua code with some XTest scrip (xdotool/xte), and make it WM-independent?

#!/bin/sh
xwininfo -int -root -children \
| awk -vFS='"' '/Uzbl browser/ {
                         gsub("^     ", "");
                         sub("^", "'"'"'", $2);
                         sub("$", "'"'"'", $2);
                         print $2
                       }' \
| dmenu -b -i -l 30 \
| awk '{
    print "a=clientfind({name="$0"})\n\
    awful.client.movetotag(uzbl_tag, a)\n\
    client.focus=a\n\
    a:raise()"
  }' \
| awesome-client

You also need following function defined in your rc.lua:

function clientfind (properties)
   local clients = client.get()
   local rv = nil
   for i, c in pairs(clients) do
      if match(properties, c) then
        rv = c
      end
   end
   return rv
end

-- Returns true if all pairs in table1 are present in table2
function match (table1, table2)
   for k, v in pairs(table1) do
      if table2[k] ~= v then
         return false
      end
   end
   return true
end

Note, there are multiple incompatibile versions of dmenu-vertical patch around. “dmenu -b -i -l 30” is compatibile with PLD version of vertical patch. If you use other linux distribution, probably you'll have to modify this line.

Using the max layout

Spawn new uzbl instances unfocused, in their specific tag

In the rules section of your rc.lua, add the following rule:

    { rule = { class = "Uzbl" },
      properties = { tag = tags[1][2],
                     focus = false,
                     lower = true
                   } },
Switch between uzbl instances using 'h' and 'l'

Install xdotool and bind h and l to your mapping in awesome to switch between windows:

@cbind   h                  = sh 'xdotool key "Super_L+k"'
@cbind   l                  = sh 'xdotool key "Super_L+j"'
Automatically focus new uzbl instances when opened with 't'

If you like url-from-surfraw-or-history, you may want to focus the instance that you just opened. In your uzbl config file, add:

@cbind   t                  = sh 'uri=$($HOME/.local/share/uzbl/scripts/load_url_from_surfraw.sh) && $HOME/.local/share/uzbl/scripts/launch-and-raise-uzbl.sh $uri'

And here is the script launch-and-raise-uzbl.sh:

#!/bin/sh

if test -z $1; then
    echo usage: $0 uri
    exit 1
else
    uri=$1
    uzbl-browser -u $uri &
    sleep 1
    echo " \
    for k, c in pairs(client.get()) \
        do if c.pid == $! then \
            client.focus = c ;\
            c:raise () \
        end \
    end \
    " | awesome-client
fi
awesome.txt · Last modified: 2016/08/31 14:10 (external edit)