Re: Is there a special variable for the directory where the script is in?

2010-02-12 Thread Guillaume Outters
Greg a écrit :

> Except that HP-UX 10.20 and HP-UX 11.11 don't have readlink(1).
> (Maybe it's added in 11.2x?  I don't know.)

You're right. I must admit I made a concession to some GNU coreutils tools on 
the platform. I once used some ls -l "$SCRIPTS" | sed -e 's/.* -> //' magic to 
replace it (and it worked two minutes ago on the HP-UX, just like it used to 
back in the old days).

-- 
Guillaume




Re: Is there a special variable for the directory where the script is in?

2010-02-12 Thread Guillaume Outters
Marc a écrit :

>source  $(dirname "$0")/functions.sh

I usually begin all my scripts with this beast:

absolutiseScripts() { SCRIPTS="$1" ; echo "$SCRIPTS" | grep -q ^/ || 
SCRIPTS="`dirname "$2"`/$SCRIPTS" ; } ; absolutiseScripts "`command -v "$0"`" 
"`pwd`/." ; while [ -h "$SCRIPTS" ] ; do absolutiseScripts "`readlink 
"$SCRIPTS"`" "$SCRIPTS" ; done ; SCRIPTS="`dirname "$SCRIPTS"`"

I use it with bash on Mac OS X, FreeBSD, Linux, and it seems (just tested now 
at work) that HP/UX 11 with its bare sh can handle it.

It does a lot of symlink-resolution, because I typically store my scripts in an 
src/scripts directory, with symlinks from $HOME/bin/tagadatsointsoin to 
$HOME/src/scripts/tagadatsointsoin.

-- 
Guillaume




UTF-8-MAC completion 13 bytes away from being perfect

2010-01-05 Thread guillaume . outters
Configuration Information [Automatically generated, do not change]:
Machine: powerpc
OS: darwin8.11.0
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='powerpc' 
-DCONF_OSTYPE='darwin8.11.0' -DCONF_MACHTYPE='powerpc-apple-darwin8.11.0' 
-DCONF_VENDOR='apple' -DLOCALEDIR='/usr/local/bash-4.1.0/share/locale' 
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -DMACOSX   -I.  -I. -I./include 
-I./lib   -g -O2
uname output: Darwin asterix.local 8.11.0 Darwin Kernel Version 8.11.0: Wed Oct 
10 18:26:00 PDT 2007; root:xnu-792.24.17~1/RELEASE_PPC Power Macintosh powerpc
Machine Type: powerpc-apple-darwin8.11.0

Bash Version: 4.1
Patch Level: 0
Release Status: release

Description:
Completion on accented filenames in Mac OS X works nicely now (and I 
find the hook a very elegant solution!). Well, except in a two-stage 
completion: after first completion attempt, any accents added by readline's 
completion breaks subsequent completions.

Repeat-By:
Have directory perso containing a Délires and a Débogage.
> ls perso/Dé
Délire/ Débogage/
OK, so we add a "b" and try again to complete:
> ls perso/Déb
(-- no output --)

Fix:
On lib/readline/complete.c, at line , replace "entry->d_name" by 
"convfn".

Explanation:
Keyboard input and bash internal handling are made in UTF-8 NFC. 
Mac OS X FS uses UTF-8 NFD.
So, first "> ls" (coming from keyboard) is NFC. readline reads perso/, 
gets Délires and Débogage in NFD, transforms them with 
rl_filename_rewrite_hook to convfn. They are now in NFC, and match with the 
input line.
So readline decides to output those matches, and replaces the input 
line by the longest common match. But in this replacement, it uses 
entry->d_name (NFD). So the input line is replaced with its NFD equivalent.
Thus on the next completion, on "perso/Déb", input is composed of this 
broken "perso/Dé" in NFD, followed by our keyboard-input "b". This NFD string 
does not match anymore with perso/Débogage in NFC (FS NFD "Débogage" 
rewritten by rl_filename_rewrite_hook).




Mac OS X Unicode NFD filesystems and bash completion

2009-07-14 Thread Guillaume Outters

Configuration Information [Automatically generated, do not change]:
Machine: powerpc
OS: darwin8.11.0
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='powerpc' - 
DCONF_OSTYPE='darwin8.11.0' -DCONF_MACHTYPE='powerpc-apple- 
darwin8.11.0' -DCONF_VENDOR='apple' -DLOCALEDIR='/usr/local/ 
bash-3.2.9/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H - 
DMACOSX   -I.  -I. -I./include -I./lib   -g -O2
uname output: Darwin asterix.local 8.11.0 Darwin Kernel Version  
8.11.0: Wed Oct 10 18:26:00 PDT 2007; root:xnu-792.24.17~1/ 
RELEASE_PPC Power Macintosh powerpc

Machine Type: powerpc-apple-darwin8.11.0

Bash Version: 3.2
Patch Level: 9
Release Status: release

Description:
See:
http://www.mail-archive.com/bug-bash@gnu.org/msg04073.html
Mac OS X, when listing directories, reports filenames in
UTF-8 NFD. With an UTF-8 configured input, bash receives
strings in UTF-8 NFC. Thus its filename completion cannot
match input strings with filesystem entities when accents
occur.

Repeat-By:
cd /tmp
mkdir Réseau
ls Ré
(Réseau is not proposed as possible completion)

Fix:
I have come up with a fix that works great on my system,
using iconv (bundled with Mac OS X, anyway).
I'm wondering though:
- Does it work well on "alternate" filesystems (is NFD
  done on OS level, or is it driver dependent?). If someone
  on the list has NTFS-3G-mounted disks or SSHFS, can he/she
  test that at least there is no loss in functionality?
- Is it Mac OS X specific? I think Darwin has the same VFS
  layer. In this case, is there a more general replacement
  for #ifdef MACOSX?
- iconv could certainly be detected in a cleaner way as I
  did (forcefully adding it to link libs, and implying it
  from MACOSX preprocessing define).
Tested with Terminal (UTF-8: works; non-UTF-8: does not
complete, so not better than before but that's normal) and
xterm.

I have put the patch here (diff -u format):
http://ks31107.kimsufi.com/gui/bash-mac-filename-completion.patch
I have made it for bash 3.2.9, it runs unmodified on a
3.2.49, and I now use it on a 4.0.24 (patch utility
detected a 83-lines offset and ran happily)