Skip to content

Instantly share code, notes, and snippets.

@skagedal skagedal/simulator.zsh
Last active Mar 14, 2019

Embed
What would you like to do?
Extension for zsh that gives an auto-completable cd to a simulator data container of the app with the given bundle identifier.
# Extension for zsh that cd to a simulator data container of the app with the given bundle identifier.
#
# See blog post at https://skagedal.github.io/2018/01/02/simcd.html
function simdir () {
xcrun simctl get_app_container booted $1 data
}
function simcd () {
cd `simdir $1`
}
function simpushd () {
pushd `simdir $1`
}
function simopen() {
open `simdir $1`
}
function _bundle_identifiers () {
xcrun simctl listapps booted | plutil -convert json - -o - | ruby -r json -e 'puts JSON.parse(STDIN.read).keys'
}
_simdir() {
local state
_arguments \
'1: :->bundle_identifier'\
'*: :->rest'
case $state in
(bundle_identifier) _arguments '1:Bundle identifier:($(_bundle_identifiers))' ;;
(*) compadd "$@"
esac
}
compdef _simdir simdir simcd simpushd simopen
@AliSoftware

This comment has been minimized.

Copy link

commented Jan 3, 2018

Tip: to list the CFBundleIdentigiers, instead of using a grep + cut + grep hack, you could instead use this, to convert the PLIST to a proper JSON then use ruby to parse and extract the keys from the JSON. Returns the same list of identifiers, but much cleaner.

xcrun simctl listapps booted | plutil -convert json - -o - | ruby -r json -e 'puts JSON.parse(STDIN.read).keys'

@skagedal

This comment has been minimized.

Copy link
Owner Author

commented Jan 5, 2018

@AliSoftware Good call, post and gist updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.