Last active
February 15, 2021 14:42
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 Good call, post and gist updated!
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[]'
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
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'