Search this site





Shebang (#!) fix.

Most shebang implementations seem to behave contrary to my expectations.

As an example, prior to today, I would have expected the following script to output 'debug: true'

#!/usr/bin/env ruby -d
puts "debug: #{$DEBUG}"
Running it, I get this:
% ./test.rb
/usr/bin/env: ruby -d: No such file or directory
This is because the 'program' executed is '/usr/bin/env' and the first argument passed is 'ruby -d', exactly as if you had run: /usr/bin/env "ruby -d"

My expectation was that the above would behave exactly like this:

% /usr/bin/env ruby -d test.rb
debug: true
It doesn't. The workaround, however, is pretty trivial. It's only a few lines of C to get me a program that works as I want. I call the program 'shebang'. Why is it C and not a script? Because most platforms have a requirement that the program being executed from the shebang line be a binary, not another script.

#!/usr/local/bin/shebang ruby -d
puts "debug: #{$DEBUG}"
Now run the script again, with our new shebang line:
% ./test.rb
debug: true
Simple and works perfectly.

ZSH: Disable 'cd' supporting usernames

I have a directory called "lib". If I try to do "cd l<tab>", zsh will offer me "libuuid list lib" as completion candidates. The words 'libuuid' and 'list' show up because they are usernames. This is really annoying, and there doesn't seem to be an option to disable this. What happend to doing "cd ~root" to change to root's homedir? Was typing '~' too hard?

At any rate, I figured out where to fix the unfeature: A file '_tilde' in path/to//zsh/4.3.4/functions/Completion/Zsh. It happens to be /usr/share/zsh/4.3.4/functions/Completion/Zsh on my ubuntu workstation.

... around line 22 ...
while _tags; do
  _requested users && _users "$suf[@]" "[email protected]" && ret=0

  _requested named-directories expl 'named directory' \
Comment out the bold line above (starting '_requested users ...') and restart zsh. This only disabled the username completion part of zsh's cd command, but that's good enough for now. If I ever accidentally typo and cd to someone's home directory, I can just popd to return to my previous location.