1

While I am doing iOS development, I find it useful to open the following file:

/Users/disappearedng/Library/Application Support/iPhone Simulator/6.1/Applications/B957F50E-CF57-4797-AA14-C580F5596E56/Documents/MyApp.sqlite

currently I have the following aliased in my bash_profile:

alias cdi='cd /Users/disappearedng/Library/Application\ Support/iPhone\ Simulator/6.1/Applications'

The reason why I have to stop here is because every new install of the app on my iOS simulator the hash, B957F50E-CF57-4797-AA14-C580F5596E56, will change.

Does anyone know of a good way to alias this so that I can alias the following to a command in my bash_profile?

'/Users/disappearedng/Library/Application Support/iPhone Simulator/6.1/Applications/<any-hash>/Documents/*.sqlite'

I tried using wildcard for the has but the existence of the .DS_Cache file in the folder has cause this to fail.

xjq233p_1
  • 7,810
  • 11
  • 61
  • 107

4 Answers4

2

This is obviously only something you want during development when running in the simulator. Why not have your app, on startup, get the path to the file and then write the path to a file in your home directory. Update your .bash_profile to source this file.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#if TARGET_IPHONE_SIMULATOR
    NSString *sqlitePath = ... // path to the Documents folder
    NSString *command = [NSString stringWithFormat:@"alias cdi='cd %@'", sqlitePath];
    [sqlitePath writeToFile:@"/Users/disappearedng/.sqlitePath" atomically:YES encoding:NSUTF8StringEncoding error:nil];
#endif
}

Then in your .bash_profile, do:

. ~/.sqlitePath
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Interesting solution. This might be hard considering we are developing this app as a team and retrieving our bash username from the app itself might be difficult. But definitely interesting! – xjq233p_1 Feb 27 '13 at 00:42
0

How about:

find /Users/disappearedng/Library/Application Support/iPhone Simulator/6.1/Applications/.{38}/Documents/MyApp.sqlite | xargs <your_text_editor>
Bryan Glazer
  • 852
  • 1
  • 10
  • 20
0

If there are more than one matching directories, and you want to enter the newest one, use this script:

cd "$(find "/Users/disappearedng/Library/Application Support/iPhone Simulator/6.1/Applications/" -name '*.sqlite' -type d -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ")"
user000001
  • 32,226
  • 12
  • 81
  • 108
  • 1
    @EeroHelenius With `ls`, he would need to filter for directories. It would also have to be recursive. It is generally considered bad practice to [parse the output of ls](http://mywiki.wooledge.org/ParsingLs), but if `printf` is not available I guess it is the only option... – user000001 Feb 26 '13 at 21:43
  • Interesting about parsing the output of `ls`, didn't know that; thanks for the link. And yes, I was a bit hasty in my first reply, sorry about that; something like `cd "$DIRNAME" && cd "$(ls -t1 -d */ | head -1)"` is what I meant to post. (And yeah, `-printf` [isn't available on OS X](http://stackoverflow.com/a/752893/825783)). – Eero Helenius Feb 26 '13 at 21:47
  • Yea that would probably work... Didn't know that about OSX - too bad! – user000001 Feb 26 '13 at 21:53
  • You could install the `findutils` package with Homebrew and then use `gfind` instead of `find` if you're so inclined, of course — `gfind` is GNU find and therefore does support `-printf`. – Eero Helenius Feb 26 '13 at 22:05
0

You can try adding .DS_Cache to the FIGNORE shell parameter. That way, the wild card should match just one directory, and the cd will still work. In your .bashrc file:

# To avoid adding .DS_Cache multiple times, just to be safe
[[ $FIGNORE =~ .DS_Cache ]] || FIGNORE="$FIGNORE:.DS_Cache"
chepner
  • 497,756
  • 71
  • 530
  • 681