Get last created workspace of user via CLI

From https://discord.com/channels/747933592273027093/971231372373033030/1245469675895394325 - @joshiscool --- Hi, is there any easy way to see when a workspace is created? I know its in the json output of coder ls but it would be nice if it was in a more accisble place. an engineer on my team creates alot of workspaces and wants to open the latest one she created, basically. I told her to run
coder ls -o json | jq '[.[] | {name, created_at}]'
coder ls -o json | jq '[.[] | {name, created_at}]'
But this feels subopitmal
16 Replies
Codercord
Codercord4mo ago
Category: Help needed Product: Coder OSS (v2) What platform are you hosting Coder OSS (v2) on?
joshiscool
joshiscool4mo ago
thanks!!
Phorcys
Phorcys4mo ago
other than that, I think your best bet would be to use the API
joshiscool
joshiscool4mo ago
for sure
Phorcys
Phorcys4mo ago
i'm looking at the docs to see what can be done
joshiscool
joshiscool4mo ago
thank you!!
Phorcys
Phorcys4mo ago
okay, turns out that the only relevant API endpoint (List Endpoints) is already the one that coder ls uses
Phorcys
Phorcys4mo ago
though apparently you can pass a query to coder ls, maybe this can help narrow the search a bit
Phorcys
Phorcys4mo ago
it doesn't really seem that we can "get latest workspace", we can only really sort by workspace owner, template name and workspace status
joshiscool
joshiscool4mo ago
yeah, no prob, I think the CLI trick is good enough for now thanks
Phorcys
Phorcys4mo ago
oh actually unless she has favorites, the running workspaces are bumped at the top of the list meh -- still requires some filtering so might aswell use created_at maybe this is a bit better :
coder ls -o json | jq '[.[] | {name, created_at}] | sort_by(.created_at)[-1].name'
coder ls -o json | jq '[.[] | {name, created_at}] | sort_by(.created_at)[-1].name'
Phorcys
Phorcys4mo ago
No description
joshiscool
joshiscool4mo ago
thanks!!
Phorcys
Phorcys4mo ago
let us know if you figure out something better :-) i will mark this thread as resolved
Want results from more Discord servers?
Add your server