Per abilitare quindi passare una cartella alias ho trovato quanto segue al Mac OS X Hints .
Compilare il codice sorgente di seguito con il seguente comando:
gcc -o getTrueName -framework Carbon getTrueName.c
Ciò creerà l'eseguibile 'getTrueName' nella stessa directory dell'origine. Puoi aggiungerlo al tuo PERCORSO o semplicemente copiarlo direttamente in / usr / bin o / usr / local / bin in modo che sia di facile accesso.
Codice sorgente C per getTrueName (copia il testo e salva il file come getTrueName.c nella tua home directory):
// getTrueName.c
//
// DESCRIPTION
// Resolve HFS and HFS+ aliased files (and soft links), and return the
// name of the "Original" or actual file. Directories have a "/"
// appended. The error number returned is 255 on error, 0 if the file
// was an alias, or 1 if the argument given was not an alias
//
// BUILD INSTRUCTIONS
// gcc-3.3 -o getTrueName -framework Carbon getTrueName.c
//
// Note: gcc version 4 reports the following warning
// warning: pointer targets in passing argument 1 of 'FSPathMakeRef'
// differ in signedness
//
// COPYRIGHT AND LICENSE
// Copyright 2005 by Thos Davis. All rights reserved.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free
// Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307 USA
#include <Carbon/Carbon.h>
#define MAX_PATH_SIZE 1024
#define CHECK(rc,check_value) if ((check_value) != noErr) exit((rc))
int main ( int argc, char * argv[] )
{
FSRef fsRef;
Boolean targetIsFolder;
Boolean wasAliased;
UInt8 targetPath[MAX_PATH_SIZE+1];
char * marker;
// if there are no arguments, go away
if (argc < 2 ) exit(255);
CHECK( 255,
FSPathMakeRef( argv[1], &fsRef, NULL ));
CHECK( 1,
FSResolveAliasFile( &fsRef, TRUE, &targetIsFolder, &wasAliased));
CHECK( 255,
FSRefMakePath( &fsRef, targetPath, MAX_PATH_SIZE));
marker = targetIsFolder ? "/" : "" ;
printf( "%s%s\n", targetPath, marker );
exit( 1 - wasAliased );
}
Includi quanto segue in ~ / .bash_profile o crea un nuovo file ~ / .bash_profile con il seguente contenuto:
function cd {
if [ ${#1} == 0 ]; then
builtin cd
elif [ -d "${1}" ]; then
builtin cd "${1}"
elif [[ -f "${1}" || -L "${1}" ]]; then
path=$(getTrueName "$1")
builtin cd "$path"
else
builtin cd "${1}"
fi
}
Probabilmente dovrai riavviare Terminal per caricare il tuo .bash_profile modificato.
Testato su Yosemite 10.10.2 e gcc 4.2 (Xcode 6.2) e funziona.
Un approccio simile è disponibile su superuser.com