Search Results: "ag"

14 October 2007

Mike Hommey: Adding some VCS information in bash prompt

I don’t spend a lot of time customizing my “working” environment nowadays, like enhancing vim configuration, or tweaking the shell. But when I read MadCoder’s zsh git-enabled prompt, I though it was too convenient to not have something like that. Except I don’t work with git only (sadly, but that’s changing), and I don’t like colours in prompt (and a 2 lines prompt is too much). Anyways, since I have a bunch of directories in my $HOME that contain either svk, svn, mercurial, or git working trees, I thought it would be nice to have some information about all this on my prompt. After a few iterations, here are the sample results:
mh@namakemono:~/dd/packages$
mh@namakemono:(svn)~/dd/packages/iceape[trunk:39972]debian/patches$
mh@namakemono:(svk)~/dd/packages/libxml2[trunk:1308]include/libxml$
mh@namakemono:(hg)~/moz/cvs-trunk-mirror[default]uriloader/exthandler$
mh@namakemono:(git)~/git/webkit[debian]JavaScriptCore/wtf$
The script follows, with a bit of explanation intertwined.
_bold=$(tput bold)
_normal=$(tput sgr0)
tput is a tool I only dicovered recently, and avoids the need to know the escape codes. There are also options for cursor placement, colours, etc. It lies in the ncurses-bin package, if you want to play with it.
__vcs_dir()
  local vcs base_dir sub_dir ref
  sub_dir()
    local sub_dir
    sub_dir=$(readlink -f "$ PWD ")
    sub_dir=$ sub_dir#$1
    echo $ sub_dir#/
  
We declare as much as possible as local (even functions), so that we avoid cluttering the whole environment. sub_dir is going to be used in several places below, which is why we declare it as a function. It outputs the current directory, relative to the directory given as argument.
  git_dir()
    base_dir=$(git-rev-parse --show-cdup 2>/dev/null) return 1
    base_dir=$(readlink -f "$base_dir/..")
    sub_dir=$(git-rev-parse --show-prefix)
    sub_dir=$ sub_dir%/
    ref=$(git-symbolic-ref -q HEAD git-name-rev --name-only HEAD 2>/dev/null)
    ref=$ ref#refs/heads/
    vcs="git"
  
This is the first function to detect a working tree, for git this time. Each of these functions set the 4 variables we declared earlier: vcs, base_dir, sub_dir and ref. They are, respectively, the VCS type, the top-level directory of the working tree, the current directory, relative to base_dir, and the branch, revision or a reference in the repository, depending on the VCS in use. These functions return 1 if the current directory is not in a working tree of the currently considered VCS.
The base directory of a git working tree can be deduced from the result of git-rev-parse --show-cdup, which gives the way up to the top-level directory, relative to the current directory. readlink -f then gives the canonical top-level directory. The current directory, relative to the top-level, is simply given by git-rev-parse --show-prefix.
git-name-rev --name-only HEAD gives a nice reference for the current HEAD, especially if you’re on a detached head. But this can turn out to do a lot of work, introducing a slight lag when you cd for the first time in the git working tree, while most of the time, the HEAD is just a symbolic ref. This is why we first try git-symbolic-ref --name-only HEAD.
  svn_dir()
    [ -d ".svn" ] return 1
    base_dir="."
    while [ -d "$base_dir/../.svn" ]; do base_dir="$base_dir/.."; done
    base_dir=$(readlink -f "$base_dir")
    sub_dir=$(sub_dir "$ base_dir ")
    ref=$(svn info "$base_dir" awk '/^URL/ sub(".*/","",$0); r=$0 /^Revision/ sub("[^0-9]*","",$0); print r":"$0 ')
    vcs="svn"
  
Detecting an svn working tree is easier : it contains a .svn directory, be it top-level or sub directory. We look up the top-level directory by checking the last directory containing a .svn sub directory on the way up. This obviously doesn’t work if you checkout under another svn working tree, but I don’t do such things.
For the ref, I wanted something like the name of the directory that has been checked out at the top-level directory (usually “trunk” or a branch name), followed by the revision number.
  svk_dir()
    [ -f ~/.svk/config ] return 1
    base_dir=$(awk '/: *$/ sub(/^ */,"",$0); sub(/: *$/,"",$0); if (match("'$ PWD '", $0"(/ $)")) print $0; d=1; /depotpath/ && d == 1 sub(".*/","",$0); r=$0 /revision/ && d == 1 print r ":" $2; exit 1 ' ~/.svk/config) && return 1
    ref=$ base_dir##*

    base_dir=$ base_dir%%
*
    sub_dir=$(sub_dir "$ base_dir ")
    vcs="svk"
  
svk doesn’t have repository files in the working tree, so we would have to ask svk itself if the current directory is a working tree. Unfortunately, svk is quite slow at that (not that it takes several seconds, but that induces a noticeable delay to display the prompt), so we have to parse its config file by ourselves. We avoid running awk twice by outputing both the informations we are looking for, separated by a carriage return, and then do some tricks with bash variable expansion.
  hg_dir()
    base_dir="."
    while [ ! -d "$base_dir/.hg" ]; do base_dir="$base_dir/.."; [ $(readlink -f "$ base_dir ") = "/" ] && return 1; done
    base_dir=$(readlink -f "$base_dir")
    sub_dir=$(sub_dir "$ base_dir ")
    ref=$(< "$ base_dir /.hg/branch")
    vcs="hg"
  
I don’t use mercurial much, but I happen to have exactly one working tree (a clone of http://hg.mozilla.org/cvs-trunk-mirror/), so I got some basic information. There is no way we can ask mercurial itself for information, it is too slow for that (main culprit being the python interpreter startup), so we take the informations we can (and since I don’t know much about mercurial, that’s really basic). Note that if you’re deep in the VFS tree, but not in a mercurial working tree, the while loop may be slow. I didn’t bother much looking for a better solution.
  git_dir
  svn_dir
  svk_dir
  hg_dir
  base_dir="$PWD"
Here we just run all these functions one by one, stopping at the first that matches. Adding some more for other VCS would be easy.
  echo "$ vcs:+($vcs) $ _bold $ base_dir/$HOME/~ $ _normal $ vcs:+[$ref]$ _bold $ sub_dir $ _normal "

PS1='$ debian_chroot:+($debian_chroot) \u@\h:$(___vcs_dir)\$ '
Finally, we set up the prompt, so that it looks nice with all the gathered information. Update: made the last lines of the script a little better and factorized.

John Goerzen: My New Printer

Yesterday, Terah and I were in a store selling used items. I spotted a good deal: a used printer for $25. Here are some of its features: Here are some photos:
img_3705.jpg
img_3707.jpg
img_3706.jpg

Christian Perrier: RWC: why did France lose...

...at least, in my opinion (which is obviously biased, let's admit that). There are several reasons for this loss: Some *bad* reasons for the English victory:

Otavio Salvador: git-update-debian-changelog deprecated! Use git-dch!

I’ve get in touch with Guido and explained him some missing things I had found on git-dch (part of git-buildpackage). The most amazing thing is that he implemented them all and his code is much nicer then mine since it has been wrote using the Python extensions for the GIT. Please, migrate your scripts that use git-update-debian-change (if there’s someone else then me using it) to use git-dch since I’ll drop it next week.

13 October 2007

Steve Kemp: Well! My manner is vague and aloof

For future reference: I will ensure this is kept up to date. (Prompted by an unscheduled outage which I'm really annoyed about!)

Romain Francoise: Everybody loves fruit salad

So if, like me, you find git-diff's default colors a bit flashy, here's how to have the same set of colors as in vim and quilt:
[color]
diff = auto
[color "diff"]
new = cyan
old = magenta
frag = yellow
meta = green
commit = normal
(This goes into ~/.gitconfig.)

Dirk Eddelbuettel: Makin' Tracks 2007

This morning was the annual Makin' Tracks 5k. As this starts three blocks from my house, supports the track at Concordia, a small college up the street from me, and runs right through my immediate neighbourhood, it's hard not to participate. This year was of course not even a week after the somewhat eventful Chicago Marathon in record-heat so I wasn't sure how well I'd do. Once again, I started way too fast and ran two miles at a 6:00 min/mile pace that I couldn't sustain just a week after a (arguably slow but still full distance) marathon, so I slowed down and finished at 19:41.7 or so for a pace of 6:23, or about eight seconds slower than my best time from last year (when we ran before the marathon). Onto the Frank Lloyd Wright 5k/10k next week, then!

Daniel Burrows: Mercurial repositories for the aptitude Debian tree now publically accessible

Since I switched the aptitude repositories over to Mercurial, I've been using hg-buildpackage to produce Debian packages. I wasn't sure at first if it would work out, so I didn't publish the repositories, and then I got swamped with work. But I've had good luck so far with hg-buildpackage, so I've uploaded the Mercurial trees to Alioth. You can find the upstream branch here:

http://hg.debian.org/hg/aptitude/debian-upstream

and the Debian branch here:

http://hg.debian.org/hg/aptitude/debian

Christian Perrier: RWC: One of the worst games of this World Cup

So, A completely non-existing French team lost against a....nearly completely non-existing English team. Too many bad decisions, too much bad kick play, too many lost balls....and even no luck (the English try...damn). The French team couldn't win with such poor play (even when they were leading by 9-8, we both were completely sure they would lose on a penalty kick). What's pretty sad is that England nearly showed nothing too and, therefore, both teams made this the worst match I've seen in that world cup. Hopefully, Argentina and South Africa will show some better play tomorrow. However, when I see this, I nearly regret that France eliminated New Zealand. The All Blacks could never have played as bad as France did and they would certainly have kicked out that boring English team. Definitely, I'll be South African or Argentinian next Sunday (I have a small preference for being Argentinian, indeed).

Julien Valroff: ndiswrapper and WPA

I had been using ndiswrapper with a Netgear WG511 PCMCIA card[1] without any problems for a while, then have begun to get kernel crashes, which were more and more frequent. I have thus backported to Etch the 1.47 version available in Sid, which *does* fix my kernel crashes. However, this newer version has brought new problems: with a “high” network load, the module just crashes silently, and has to be reloaded so that the network connection can be enabled again. I have packaged ndiswrapper 1.48 as the release notes let me think my issues were fixed (”Disassocation with wpa_supplicant is fixed”), but the problem is still there with this latest release! I have finally managed to get things work correctly thanks to this post: I use Debian linux-image, ie. without preemption enabled, and I can now confirm the still-to-be-released 1.49 version fixes this issue. I have uploaded 1.49-rc3 packages to my unofficial repository just in case someone has the same issue.
Linknotes:
  1. the free prism54 unfortunately does not support WPA ↩

Julien Valroff: Switched to Dovecot LDA and Sieve

I have worked almost all the day to update my mail server configuration to use Dovecot LDA and the Sieve mail filtering language instead of maildrop. This was very easy thanks to Christoph’s ISP-style Email Server with Debian-Etch and Postfix 2.3 how-to.
(more…)

Daniel Burrows: Monad.Reader

The Reader monad is a simple and easy-to-use structure from the Haskell library that solves a common problem.

Very often, it's the case that you have a lot of functions that all need to use the same values. For instance, you might be laying out some text on a page, and you need to keep the details of the page size around in all your layout algorithms. Typically, you handle this situation by adding a new parameter to all your functions which represents the state. So,


layoutPage :: Text -> Page


becomes


layoutPage :: PageLayoutParams -> Text -> Page


This works just fine, but it can get really ugly. Every single function gets a new parameter, which must be threaded through to every related function that it ever calls. This causes visual clutter, particularly for functions that don't actually use the parameter themselves but just pass it on.

A function written in the Reader monad is augmented with a hidden parameter. For the hypothetical example above, we would write:


import Control.Monad.Reader
type LayoutFunc = Reader PageLayoutParams

layoutPage :: Text -> LayoutFunc Page


Note that the Reader monad is partially applied here. The result, LayoutFunc, is a new monad that adds a parameter of type PageLayoutParams to any code that runs inside it.

So, now that we have this monad, how do we use it? The "ask" operation retrieves the parameter that's hidden in the monad:


ask :: Reader a a


or, specialized to LayoutFunc:


ask :: LayoutFunc PageLayoutParams


In order to remain close to the example in question, I will provide specialized type signatures for the rest of the library functions. You can find the generic type signatures in the Haskell library documentation for Control.Monad.Reader.

Suppose that layoutPage started out like this before it was moved into the monad:


layoutPage st txt =
let width = pageWidth st
...


In the Reader monad, this becomes:


layoutPage txt =
do st - ask
let width = pageWidth st
...


As you can see, we've gone from one line of code to two. As this is clearly unacceptable for a clutter-reducing device, the Reader module provides a convenience function encapsulating the above pattern:


asks :: (PageLayoutParams -> a) -> PageLayoutFunc a


This allows us to simplify the monadic implementation to:


layoutPage txt =
do width - asks pageWidth
...


It's quite common, when multiple functions share context information, to invoke a function in an altered context. For instance, we might have a layoutSubPage routine that changes the page width:


layoutSubPage st newWidth txt =
doLayout (st pageWidth = newWidth txt)


The Reader equivalent of this idiom is the function "local":


local :: (PageLayoutParams -> PageLayoutParams) -> LayoutFunc a -> LayoutFunc a


local executes an operation in a context modified by its first parameter. For instance,


layoutSubPage newWidth txt =
local (\st -> st pageWidth = newWidth ) txt


Finally, to actually invoke a computation in the Reader monad, use runReader:


runReader :: LayoutFunc a -> PageLayoutParams -> a

main = showPage (runReader defaultPageParams someText)


For much more information on the Reader monad, see All About Monads, or the Haskell library documentation.

Eddy Petri&#537;or: SELinux: MLS/MCS support

When getting this error message:

bounty:~/usr/src/selinux/localpolicies/resolvconf# semodule -i localresovconf.pp
libsepol.link_modules: Tried to link in a non-MLS module with an MLS base.
libsemanage.semanage_link_sandbox: Link packages failed
semodule: Failed!


You have to go back to the checkmodule step and type the same command, but add also the -M parameter:

bounty:~/usr/src/selinux/localpolicies/resolvconf# checkmodule -m -M -o localresovconf.mod *.te
checkmodule: loading policy configuration from resolvconf.te
checkmodule: policy configuration loaded
checkmodule: writing binary representation (version 6) to localresovconf.mod

After that is all OK:

bounty:~/usr/src/selinux/localpolicies/resolvconf# semodule_package -o localresovconf.pp -m *.mod
bounty:~/usr/src/selinux/localpolicies/resolvconf# semodule -i localresovconf.pp
bounty:~/usr/src/selinux/localpolicies/resolvconf# semodule -l grep localresolv
localresolvconf 1.0

Biella Coleman: Decoding Liberation: The Promise of FOSS (and Web 2.0)

Last week I helped Samir Chopra and Scott Dexter kick off their book release party in New York City. The book Decoding Liberation: The Promise of Free and Open Source Software is the first academic book length piece on free software proper that among other things examines the repercussions of such elements as language use (free software vs open source) and licensing (such as non-copyleft licensing). Here are my opening remarks, which don’t give justice to the book but give a small taste of what is in there. Samir and Scott are computer scientists, philosophers, and political thinkers and bring these positions and perspectives to bear in their work. While I tend to avoid the discussion on the differences and divergences between free and open source software and licensing (just because I ask a set of questions that tend not to go into that territory), they spend a hefty about of time on this sort of engagement And what is so useful about their approach is that it is technically detailed and carefully analyzed, clarifying the stakes involved in choosing a certain set of licensing over others, or the political implications of language use. Along with this focus, there are many other threads they unpack and one of my favorites is on the aesthetics of code, which I discuss with some detail in my opening remarks with the help of one of my favorite literary writers, Susan Sontag. The conversation that followed was lively, in part because there were a number of people in the audience who are also very familiar with FOSS (Somewhat unbelievably, there were 3 anthropologists there who study free software, myself, Jelena Karanovic, and Anita Chan). And I think one of the most interesting questions was launched by Anita who asked the authors what they meant more precisely by the promise of FOSS as well as liberation. The conversation that followed was too rich to recount here, but something that I raised and I do think is important is the relationship between the buzz word of the last few years, Web 2.0 and FOSS. Web 2.0 is related to FOSS in so far as Web 2.0 refers to a suite of technologies that allow for the creation of user-generated content and collaboration. FOSS refers to a development methodology that is based on promiscuous sharing of code and collaboration. The similarities, however, end there because much of the Web 2.0 infrastructure is proprietary. FOSS by definition is non-proprietary. But I think that soon we are going to see more Web 2.0-like companies open up their infrastructure entirely or at least important components. One example of a new technology that is Web 2.0-like and is entirely free software is a activist networking tool crabgrass that is pretty impressive (I have used it to coordinate my move and am using it now to coordinate a collaborative grant). It is still under development but once released, it will be a great boon to any group that needs to collaborate and organize and coordinate:
Crabgrass also provides a public advocacy centric view of content so that people can learn more about issues and organizations through social relationships. Blog tools, voter guides, petitions, event organizing tools, and action alerts are being added to the functionality of the platform. Crabgrass integrates wikis, asset repositories, task lists, calendars, polls, and meeting schedulers into one tool which allows groups to manage their internal organizing.
The other technology that I am excited about and that I have already written about is Kaltura. As I mentioned, Kaltura is important because it lowers the bar for collaboration, providing tools to facilitate video editing. But what I find as interesting and as significant is that they are perhaps the first large-scale Web 2.0 company that is actively seeking to enter the territory of FOSS and in this respect, once they do so, they will lead the field, not simply for technical reasons, but because they choose to make and engage with open source technologies. Bringing Web 2.0 within the orbit of FOSS and brining FOSS within the orbit of Web 2.0 can only work to bolster each other, and this is where I think, at least part of the promise of FOSS lies.

Biella Coleman: On Networks and Experimental Writing

One of my dissertation thesis advisors, Christopher Kelty, is teaching a superb looking course at Harvard this fall on networks. The only thing I would add to that syllabus right now is a book by a department colleague, Alexander Galloway, who just published a book with Eugene Thacker The Exploit. And while I have not read more than a chapter, what I like about it is its experimental style. They open this book with the following orientation:
It is our intention in this book to avoid the limits of academic writing in favor of a more experimental, speculative approach. To that end, we adopt a two-tier format. Throughout Part I, “Nodes,” you will find a number of condensed, italicized header that are glued together with more standard prose. For quick immersion, we suggest skikking Part I by reading the italicized sections only…. In this sense, we hope you will experience the book not as the step-by-step propositional evolution of a complete theory but as a series of marginal claims, disconnected in a living environment of many thoughts, distributed across as many pages.
The good thing is while the form is experimental, at the sentence level, things are quite clear. I have often had the experience of reading experimental work whose content was the experiment but not the form, and basically I did not understand a thing. In this case, it is the form that achieves their desire to explore and present their marginal claims. Annemarie Mol in The Body Multiple also uses a two-tiered experimental approach that is just fantastic, especially since her writing is especially accessible.

Clint Adams: One of us does not get it

Rapha l, I'm not sure you understood. The solution is to get rid of all of DSA (and maybe anyone that supports them). Removing one side of a power struggle may win you some short term gains, but may be a no-op or even more harmful in the long run. Such a solution is indicative of what I would call an overly-practical mindset, the kind I'd expect from Project Scud. You can say that DSA's inadequacies and ineptitude are due to specific individuals, but it is a team: each member is free to quit at any time (unless there is some kind of sinister blackmail or other means of coercion in progress, in which case I'm sure we would all appreciate if you exposed it), and each member is responsible for the performance of the team. If you accept that each team member is responsible, and you acknowledge that DSA's behavior is unacceptable, then how can you imagine that adding or subtracting members piecemeal will effect anything substantial?

Raphael Geissert: Blog Action Day

What about one day on which every blog posts on the same subject: the environment


On October 15th don't forget to blog about the environment: what you do not to polute very much, how you care about the environment in your day-a-day life, or whatever you want to say about the environment.

The mission is to have mass participation worldwide, so don't forget to spread the word and check out this video.



Visit http://blogactionday.org/ for more information :).

I'm looking forward to see Planet Debian full of environment-related blog posts on October 15th :yes:

John Goerzen: Young People NOT Delinquent?

Here's an interesting and probably controversial article. It starts with:

When I hear people my age (35+) rip the younger generation I usually keep my mouth shut. But I have something I need to say, so this is my public response to the people who think there is something wrong with young people today.

Let me tell you what I think about young people:

The kids coming of age right now are the greatest generation, and we don t give them the respect and freedom we were given and it is shameful.


And it goes on from there.

Also I should point out that George Bush is a baby boomer.

Joey Hess: more mr fun

I've hacked a lot of handy features into mr. Some more examples follow. I've ommitted noisy output from the various revision control systems. Registering existing repos:
joey@kodama:~/tmp/scratch> git clone git://git.kitenet.net/mr
joey@kodama:~/tmp/scratch> svn co svn://svn.kitenet.net/joey/trunk/src/packages/alien
joey@kodama:~/tmp/scratch> mr register mr
Registering git url: git://git.kitenet.net/mr
joey@kodama:~/tmp/scratch> mr register alien
Registering svn url: svn://svn.kitenet.net/joey/trunk/src/packages/alien
joey@kodama:~/tmp/scratch> mr up
mr update: /home/joey/tmp/scratch/alien
At revision 13492.
mr update: /home/joey/tmp/scratch/mr
Already up-to-date.
mr update: finished (2 successful)
Command-line modification of the ~/.mrconfig file, and the ability to skip a repo based on an arbitrary shell test:
joey@kodama:~/tmp/scratch> mr config tmp/scratch/alien skip='[ $(hostname) != foo]'
joey@kodama:~/tmp/scratch> mr up
mr update: /home/joey/tmp/scratch/mr
Already up-to-date.
mr update: finished (1 successful; 1 skipped)
Tracking and warning about deleted repositories. Useful if, like me, you have dozens of repos checked out on dozens of machines:
joey@kodama:~/tmp/scratch> mr config tmp/scratch/mr deleted=true 
joey@kodama:~/tmp/scratch> mr up
mr error: /home/joey/tmp/scratch/mr/ should be deleted yet still exists
mr update: finished (1 failed; 1 skipped)
joey@kodama:~/tmp/scratch> rm -rf mr
joey@kodama:~/tmp/scratch> mr up
mr update: finished (1 skipped)
(Tracking of repo moving is still TODO.) Running mr from inside a repo operates on only that repo. Useful when you can't be bothered to remember what revision control system a particular repo uses. ;-)
joey@kodama:~/src/mr/debian> mr commit -m "bugfixes developed while writing blog post"
mr commit: /home/joey/src/mr (in subdir /home/joey/src/mr/debian)
Created commit 2f861a4: bugfixes developed while writing blog post
It also supports cvs and bzr now.

Erinn Clark: Pink offends Gnome users

Actual results: Pink ugliness. That's how I feel about the overtly masculine blue hegemony in almost every website and window manager theme I encounter.

Next.

Previous.