Opening files from the terminal in BAS dev spaces

| 2 min read

In the comments to episode 4 of our back to basics series of live stream episodes on CAP, on the Hands-on SAP Dev show, there was a question on my use of code in VS Code, which, when invoked in the terminal (e.g. code services.cds) opens the file directly in a VS Code editor window, like this:

opening a file from the terminal in VS Code

The question was about code being recognised in SAP Business Application Studio (BAS) dev spaces.

Basically, while code is not a command that's available in dev spaces, there's a BAS-specific command basctl which has a couple of options, one of which is --open. Here are some examples, taken from the usage text:

Examples
$ basctl --open http://sap.com
$ basctl --open http://localhost:8082/tmp
$ basctl --open file:///home/user/projects/proj1/myfile.txt
$ basctl --open /myfile.txt
$ basctl --open ./myfolder/myfile.txt

So while there isn't a code command, you can use basctl --open to get something similar. I say similar, because for some reason I cannot yet fathom (my small brain, again) it opens the file in a new column. Anyway, here's what it looks like in action:

opening a file from the terminal in a BAS dev space

(I've asked internally about this behaviour, and will update this blog post with anything I find out.)

(Update 05 Mar 2024: It turns out this was unintended behaviour, which my question internally highlighted, and the behaviour has now been fixed - see pull request 299 in the app-studio-toolkit repo. The fix will reach production environments by the middle of this month.)

The nice thing about what basctl offers perhaps is the ability to invoke framework commands, via an additional --command option, like this: basctl --command workbench.action.openSettings.

The question also asked about my use of tree, and noted its lack of availability in BAS dev spaces. This is simple to address, if not entirely straightforward. I got tree working in my dev space, as you can see:

tree running in my BAS dev space

I did this by copying in a tree binary (and ensuring the execution bit was set). Where did I get that tree binary from? Well, first, I looked what the architecture of the dev spaces was, via uname (I've added whitespace for readability):

user: user $ uname -a
Linux workspaces-ws-nvzxc-deployment-9f9b9b656-sfdh5
5.15.135-gardenlinux-cloud-amd64
SMP Debian 5.15.135-0gardenlinux1 (2023-10-12)
x86_64 GNU/Linux

I also checked what distribution the environment was based on:

user: user $ cat /etc/issue
Debian GNU/Linux 12 \n \l

Basically, it's Debian 12 on x86_64 architecture. Classic. So then I created a quick container from a Debian 12 based container image, via a codespace that I spun up for the purpose, and copied the tree binary out of there to my local filesystem, like this:

gh codespace cp 'remote:/usr/bin/tree' .

I then copied that binary to the dev space by dragging it into the Explorer window, and then set the execution bit with chmod +x $HOME/tree.

Job done!


Update 22 Apr 2024: A colleague kindly let me know that following our use of tree on Hands-on SAP Dev and in this post, they've added the command so it's available in Dev Spaces now. Thanks team!

user: user $ hostname
workspaces-ws-bkmjx-deployment-7c95494642-ptsqw
user: user $ tree
.
|-- node_modules -> /extbin/generators/lib/node_modules
|-- projects
`-- tmp -> /tmp/usertemp/tmp

3 directories, 1 file