lorenzo bolla’s blog

January 9, 2010

surf browser hints /3

Filed under: programming — Tags: , , — lbolla @ 8:37 pm

another couple of hints about surf, after my previous post.

honestly, I stopped using surf after 0.3 release. I think that the authors stripped out of the code too much sugar that, not being suckless, was nonetheless useful: a status bar showing the current URI, for example. now URI editing is done via xprop and dmenu, which is great piece of software, but not always user friendly (it does not have editing capabilities).

moreover bookmarking is a pain as it relies on external shell scripts. or does it not?

I realized that there is no need to use external shell scripts, as they can be “embedded” in C code. Here is how.

in config.h put these lines, right before the definition of keys[]:

#define BM_PICK { .v = (char *[]){ "/bin/sh", "-c", \
"xprop -id $0 -f _SURF_URI 8s -set _SURF_URI `cat ~/.surf/bookmarks | dmenu || exit 0`", \
winid, NULL } }

#define BM_ADD { .v = (char *[]){ "/bin/sh", "-c", \
"(echo `xprop -id $0 _SURF_URI | cut -d '\"' -f 2` && cat ~/.surf/bookmarks) | sort -u > ~/.surf/bookmarks_new && mv ~/.surf/bookmarks_new ~/.surf/bookmarks", \
winid, NULL } }

then inside keys[] definition, add:

{ MODKEY, GDK_b, spawn, BM_PICK },
{ MODKEY|GDK_SHIFT_MASK,GDK_b, spawn, BM_ADD },

now, recompile. in your shiny new surf, CTRL-B pops-up dmenu with the list of bookmarks and CTRL-SHIFT-B adds the current page to the bookmarks (making sure to remove duplicate entries).

no need for shell scripts!

January 8, 2010

dwm restart

Filed under: programming — Tags: , — lbolla @ 7:14 pm

dwm is a wonderful window manager for X: it’s small, fast and stable.

the only thing I missed, until today, was the possibility to restart it without losing my X session (i.e. all the open windows, etc.). restarting dwm is something you might need to do often, as it does not have config files: changes are done by recompiling the sources.

the trick is to execute dwm in background and sleep forever!

take a look at the last two lines of my .xinitrc:

---
dwm &
sleeper
---

where sleeper looks like this:

---
#!/bin/sh
while `/bin/true`; do
sleep 1000
done
---

now, if you kill dwm (usually with ALT-SHIFT-q) the windows (and X) will still be alive and you can type dwm& in any xterm to get dwm up and running again.

if you really want to quit X, you need to kill the sleeper.

January 7, 2010

installing pcf fonts in X

Filed under: programming — Tags: , — lbolla @ 6:55 pm

as I keep forgetting, here is how to install pcf fonts in X

  1. create a new directory for the fonts, usually under /usr/share/fonts:
    $> mkdir /usr/share/fonts/
  2. copy the pcf file(s) into it (sometimes the pcf files are gzipped):
    $> cp /path/to/pcf/*.pcf* /usr/share/fonts/
  3. run mkfontdir, to create a fonts.dir file, used by X to find font files
    $> mkfontdir /usr/share/fonts/
  4. add the new dir to X font path. The easiest way to do it is to stick this line in your .xinitrc:
    xset fp+ /usr/share/fonts/

now your new font should compare in xfontsel and you should be able to use it as normal.

by the way, this is a very nice font for programming!

September 13, 2009

the List and the Truth

Filed under: links, programming — lbolla @ 1:38 pm

Spoon Boy: Do not try and bend the list. That’s impossible. Instead . . . only try to realize the truth.
Neo: What truth?
Spoon Boy: There is no list.
Neo: There is no list?
Spoon Boy: Then you’ll see that it is not the list that bends; it is only yourself

from “Practical Common Lisp

September 10, 2009

my phd thesis on scribd

Filed under: personal — Tags: , , — lbolla @ 2:12 pm

August 28, 2009

videocracy

Filed under: italiano — Tags: , , — lbolla @ 9:56 am

August 25, 2009

surf browser hints /2

Filed under: programming — Tags: , , , — lbolla @ 12:45 pm

following yesterday’s post, here is another useful hint about surf’s usage.

the following script lists the available bookmarks (from ~/.bookmarks file) and let’s you pick one using dmenu. if a new link is inserted, it is added to the list of known bookmarks, so you won’t need to type it in full the next time:

#!/bin/sh
bookmarks=~/.bookmarks
link=`cat $bookmarks | dmenu ${1+"$@"}` || exit 0
present=`grep $link $bookmarks`
if [ "$?" -ne "0" ]; then
echo $link >> $bookmarks
fi
surf -u $link

if you don’t want to open a new window, just change the last line to set the _SURF_URL X Property of the surf window you want to use (by clicking on it):

xprop -f _SURF_URL 8t -set _SURF_URL $link

August 24, 2009

surf browser hints

Filed under: programming — Tags: , , , — lbolla @ 6:13 pm

surf is a simple webbrowser based on webkit/gtk+, the same web engine that powers Google Chrome.

used with dwm and dmenu, it’s a very powerfull, yet simple tool.

here is a patch to apply X geometry hints to surf, so that surf windows behave in dwm.


*** surf.c.orig 2009-08-24 16:41:31.000000000 +0100
--- surf.c 2009-08-24 16:35:02.000000000 +0100
***************
*** 372,377 ****
--- 372,381 ----
gtk_container_add(GTK_CONTAINER(c->vbox), c->searchbar);
gtk_container_add(GTK_CONTAINER(c->vbox), c->urlbar);

+ /* Hints */
+ GdkGeometry hints = { 1, 1 };
+ gtk_window_set_geometry_hints(GTK_WINDOW(c->win), NULL, &hints, GDK_HINT_MIN_SIZE);
+
/* Setup */
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->urlbar, FALSE, FALSE, 0, GTK_PACK_START);
gtk_box_set_child_packing(GTK_BOX(c->vbox), c->searchbar, FALSE, FALSE, 0, GTK_PACK_START);

another hint is to create a script to feed surf with your favorite bookmarks. here it is:

#!/bin/sh
exe="surf -u `cat ~/.bookmarks | dmenu ${1+"$@"}`" && exec $exe

enjoy!

August 12, 2009

vim and python comments

Filed under: programming — Tags: , , — lbolla @ 5:56 pm

I’m currently undergoing a profound revision (read “cleanup”) of my .vimrc and I recently had to choose a decent plug-in to comment python code.

the best so far is EnhancedCommentify. it’s highly configurable, powerful and it supports a different number of languages (not only python).

the only one thing that wasn’t easy to setup if the behaviour described here: being able to comment a block, respecting the indent, in both visual and normal mode.

a clean solution, without the need to define any function is to stick these lines into your .vimrc:


let g:EnhCommentifyPretty='Yes'
let g:EnhCommentifyRespectIndent='Yes'
let g:EnhCommentifyUserBindings="Yes"
let g:EnhCommentifyUseBlockIndent='Yes'


vmap ,c (Plug)VisualComment
vmap ,d (Plug)VisualDeComment
vmap ,g (Plug)VisualTraditional
vmap ,f (Plug)VisualFirstLine
nmap ,c (Plug)Comment
nmap ,d (Plug)DeComment
nmap ,g (Plug)Traditional
nmap ,f (Plug)FirstLine

(but remember to change “(” to “<” and “)” to “>” — wordpress is strict about “<” and “>”…)

enjoy!

May 1, 2009

Windows’ bugs

Filed under: personal — Tags: , — lbolla @ 5:31 pm

a bug’s just hidden in my keyboard…
a green one…
under the Windows key!

Older Posts »

Blog at WordPress.com.