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
Codercord7mo ago
Category: Help needed Product: Coder OSS (v2) What platform are you hosting Coder OSS (v2) on?
joshiscool
joshiscool7mo ago
thanks!!
Phorcys
PhorcysOP7mo ago
other than that, I think your best bet would be to use the API
joshiscool
joshiscool7mo ago
for sure
Phorcys
PhorcysOP7mo ago
i'm looking at the docs to see what can be done
joshiscool
joshiscool7mo ago
thank you!!
Phorcys
PhorcysOP7mo ago
okay, turns out that the only relevant API endpoint (List Endpoints) is already the one that coder ls uses
Phorcys
PhorcysOP7mo ago
though apparently you can pass a query to coder ls, maybe this can help narrow the search a bit
Phorcys
PhorcysOP7mo 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
joshiscool7mo ago
yeah, no prob, I think the CLI trick is good enough for now thanks
Phorcys
PhorcysOP7mo 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
PhorcysOP7mo ago
No description
joshiscool
joshiscool7mo ago
thanks!!
Phorcys
PhorcysOP7mo ago
let us know if you figure out something better :-) i will mark this thread as resolved
Codercord
Codercord7mo ago
@Phorcys closed the thread.

Did you find this page helpful?