So today I learned about find -exec ... +
Posts for: #Bash
how would you read a file into an array of lines
I was working on a shell script that needed to look at some lines in a bunch of files and perform some data mining. I started it in bash, so I am writing it in bash even though dave0 notes that I should have started in in perl. Point taken… I suffer for my mistake.
After a quick google I learned that a nice way to do what the topic of this post describes can be done using
IFS='
'
declare -a foo=( $(cat $file) )
Which is great! Right?
shrinking URLs
I wrote a short script to shrink URLs:
% shorturl http://www.jukie.net/~bart/shorturl
http://2tu.us/ce8
% shorturl
Type in some urls and I'll try to shrink them for you...
http://www.jukie.net/~bart/shorturl
http://2tu.us/ce8
http://www.jukie.net/~bart/20090320214228
http://2tu.us/ce9
I am doing this as part of my new identi.ca addiction^W
usage and extending GregKH’s command line micro blogging tool.
UPDATE: also picked up by @vando for use with mcabber.
cloning xterms in wmii+ruby
I have recently added a few things to by wmii+ruby configuration that I wanted to share. These are:
- start a program in a given view from bash prompt (authored by Dave O’Neill)
- start a program in a given view using
Alt-Shift-p
(authored by Jean Richard) - start an xterm in a given view using
Alt-Shift-Return
- cache directory changes in a view, start an xterm in the view’s last directory using
Alt-Apostrophe
shell commands
I saw this blog post by Debian’s Florian Ragwitz, and ran my own list of most commonly used shell commands. Here they are…
history |awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}' | sort | uniq -c | sort -r | head -15
627 git
266 vim
98 cd
76 grep
69 ls
63 gitk
60 ssh
51 sudo
47 vv
47 apt-cache
40 cat
34 make
33 patch
30 rm
25 man
generating html colourized sourcecode
I wanted to have vim colouring of source files in html format. There is Text::VimColor perl module, but it’s not in Debian.
Vim has a :TOhtml
command (see :h syntax). I wrote a tohtml shell script to solve the problem using :TOhtml
. And yes, the html was generated with itself.
bash vi editing mode
bash comand line
For a few years now I've been using vi editing mode for bash and anything that uses readline. Here is how I've set things up.
In .bashrc I use the following to enable vi editing mode:
set -o viThis allows me to type as usual and use ESC to get into vi command mode. Since ESC is so far away I frequently use control-[... unless I feel I need the exercise.