Wednesday, October 17, 2012

shell: basename and dirname through Parameter Expansion


If you want to have basename and dirname a little faster through shell builtins, you may want to try these in bash or Korn Shell:
  • basename: ${file##*/}
  • dirname: ${file%/*}
I don't really recommend to use these substitutes, I still find basename and dirname quite readable and I am not using them in a loop anyway.

Wednesday, October 10, 2012

Emacs + putty + TRAMP = you can edit your UNIX files remotely on Windows

TRAMP User Manual

TRAMP extends the capabilities of the emacs "directory editor" (dired) to allow you to also deal with remote files. "Remote" as in:

  • you can reach the file or directory through ssh
  • or sftp
  • or ftp
  • or …
SSH on Windows – PuTTY:
On Windows platforms it can make use of the PuTTY family of utilities in order to achieve ssh and sftp tasks.

The TRAMP user manual recommends using scpc resp. pscpc instead of ssh resp. (just) plink for dealing with large files [Link]. I suggest you go for this recommendation anyway. Really! I mean it! According to my experience (having tried various ways resp. methods) plink resp. plinkx occasionally corrupt files, and you avoid that using the TRAMP method pscp, which is actually a nice combination of plinkx and PuTTY pscp, i.e. you are passing a named saved session rather than a host name to it. ("THE manual" does not mention this bit, but you should be aware of it.)

On the Windows PC at my customer's site I am not able to modify my system environment.
The putty directory is not put on PATH by the system, I am doing it within my .emacs.

Still: For some reason tramp does not search its tramp-copy-program on PATH, and at least pscp does not get found that way. The error message goes like this:
Cannot find copy program: pscp.
I found the variable tramp-methods and changed the resp. tramp-copy-program assoc to have pscp with its absolute path as its value instead of just pscptramp-methods cannot be "customized". add-to-list always only ends to the end of the list, so just adding a new try with a full-path-pscp would not have helped, so I rather changed .../emacs/lisp/net/tramp-loaddefs.el. Quick and dirty, I know. I will find a more appropriate way occasionally, I promise.

Update 2013-01-15: tramp paths with ports:
Occasionally "sitting" on a VM (VirtualBox) host I copy / access files living in a VM Linux guest, whose SSH port is forwarded to the VM host's port 2222.
VM-host $ env RSYNC_RSH='ssh -p 2222' rsync -vaz diary localhost:diary_
This is a useful emacs/tramp access path for those files:
/scpx:localhost#2222:diary

scpx and sshx as opposed to scp and ssh (without the 'x' in the end) seem to accept a port number within these emacs/tramp access paths.

Update 2013-04-30: problem with preserving emacs tramp file permissions:
Somebody else experiences this problem as well [link].

Update 2013-04-30 evening:
http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/pscp-filemodes.html : I think, this doesn't concern TRAMP, as TRAMP has its own means to enquire and set file modes.

Update 2013-10-__:
Found "vc-handled-backends" and reduced it on my Windows emacs / tramp / putty platform.

Sunday, October 7, 2012

brewing perls on my platforms

[2012-10-07 12:45:26] johayek@HayekY $ cpanm --force WWW::Curl

[2012-10-07 03:17:01] johayek@HayekY $ perlbrew --force --notest install perl-5.16.1

[2012-10-07 12:47:56] johayek@HayekU $ perlbrew --force --notest install perl-5.16.1

Saturday, October 6, 2012

O'Reilly Media book: Learning the Korn Shell, 2nd Edition

Q: The ksh on "your" AIX – is it ksh88 or ksh93?
A: Well … the ksh on "my" AIX knows the "whence" builtin without "-a", so I think it's a ksh88, because ksh93 would know "whence -a".
(This paragraph will go to another article on ksh. (TBD))

Tuesday, October 2, 2012

O'Reilly Media book: Essential System Administration, 3rd Edition

Essential System Administration, 3rd Edition - O'Reilly Media

O'Reilly Media book: sed and awk Pocket Reference, 2nd Edition

sed and awk Pocket Reference, 2nd Edition - O'Reilly Media

O'Reilly Media book: Effective awk Programming, 3rd Edition

Effective awk Programming, 3rd Edition - O'Reilly Media

O'Reilly Media book: sed & awk, 2nd Edition

sed & awk, 2nd Edition - O'Reilly Media

O'Reilly Media book: The Twitter Book

The Twitter Book - O'Reilly Media

PuTTY – Fixing Right Click Paste — EtherealMind

PuTTY – Fixing Right Click Paste — EtherealMind

No more past on clicking your right mouse button, get a menu instead!

Running PuTTY from the Windows Command Line

You want to load a particular putty session on the command line (and "hide" this in a putty shortcut)? Find the description above!

Short version:
PuTTY allows you to connect to a remote host in 2 different ways :

  • ...\putty.exe [USER@]HOST // naming the remote HOST directly
  • ...\putty.exe -load SESSION_NAME // naming the remote HOST within a named "saved session"
I prefer the latter, as you also enjoy all the other settings being part of the "named saved session".

GNU Emacs for Microsoft Windows resp. Mac OS X


O'Reilly's web page for "Learning GNU Emacs, 3rd Edition" [Link] points for Mac OS X and Windows implementations exclusively to these web pages, but pls regard both as outdated:
  • http://sourceforge.net/projects/nqmacs/
  • http://www.apple.com/downloads/macosx/unix_open_source/carbonemacspackage.html