Skip to content

Instantly share code, notes, and snippets.

@skagedal
Last active February 15, 2021 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skagedal/6fda34e0bc5f532e02dd51314554bcdd to your computer and use it in GitHub Desktop.
Save skagedal/6fda34e0bc5f532e02dd51314554bcdd to your computer and use it in GitHub Desktop.
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
@skagedal
Copy link
Author

skagedal commented Jan 5, 2018

@AliSoftware Good call, post and gist updated!

@idcrook
Copy link

idcrook commented Feb 14, 2021

thanks for this gist. if the jq utility is available, there is the even shorter:

xcrun simctl listapps booted | plutil -convert json - -o - | jq -r 'keys | .[]'
# or even 
xcrun simctl listapps booted | plutil -convert json - -o - | jq -r 'keys[]'

@skagedal
Copy link
Author

That's true, @idcrook! I wanted a solution that would work out of the box on a macOS machine though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment