-
-
Save ianloic/ddd8105da589d10760638af6f5306ae7 to your computer and use it in GitHub Desktop.
code () { | |
local script=$(echo ~/.vscode-server/bin/*/bin/code(*ocNY1)) | |
if [[ -z ${script} ]] | |
then | |
echo "VSCode remote script not found" | |
exit 1 | |
fi | |
local socket=$(echo /run/user/$UID/vscode-ipc-*.sock(=ocNY1)) | |
if [[ -z ${socket} ]] | |
then | |
echo "VSCode IPC socket not found" | |
exit 1 | |
fi | |
export VSCODE_IPC_HOOK_CLI=${socket} | |
${script} $* | |
} |
what is oc[1]N and what is the equivalent of it in bash
what is oc[1]N and what is the equivalent of it in bash
oc
sorts the item with respect to inode change time. And only get the first item by [1]
. N
sets the NULL_GLOB option for the current pattern.
So the pattern basically tries to get the most recently created/modified file.
I have no idea about the equivalent of it in bash since I'm no expert on shell scripts. Sorry for that.
Instead of using an echo with a glob you could try using ls
and head
. Something like:
local script=$(ls -1t ~/.vscode-server/bin/*/bin/code 2> /dev/null | head -1)
I haven't tested it but that should list list all of the matching files in time order with the most recent at the top, suppress any errors (for example if the glob fails) and then take just the first. It won't do the other things that the zsh glob is doing like checking that the file is executable, but that is just a nice sanity check. Bash doesn't seem to do anything clever with filename expansion, sadly: https://www.gnu.org/software/bash/manual/html_node/Filename-Expansion.html
Thank you for great post & gist. This will help me a lot.
However, I found that current script results in error like below with zsh version
zsh 5.0.5 (x86_64-suse-linux-gnu)
I had to change
ocNY1
tooc[1]N
.