Checking for a file with a specific type
In fish, you can check if a particular file exists with test -e hello.txt
, but I'm wondering if there is a way to use wildcard values ββin the filename to check for the existence of some type of file.
To be more specific, I am making a quick function that checks the Xcode workspace if open, if not then check the Xcode project and if found it will open that, otherwise print an error.
Here's the current implementation:
function xcp
open *.xcodeproj
end
function xcw
open *.xcworkspace
end
function xc
if test -e *.xcworkspace
xcw
else if test -e *.xcodeproj
xcp
else
echo "No Xcode Workspace or Project in this directory."
end
end
It "works" in a minute, but when it doesn't find a workspace or project file, it prints a no match message. However, this is done by default and I am wondering if I can somehow hide this.
Here is the error output when it doesn't find the workspace but finds the project and opens it:
No matches for wildcard '*.xcworkspace'. (Tip: empty matches are allowed in 'set', 'count', 'for'.)
~/.config/fish/functions/fish_prompt.fish (line 1): if test -e *.xcworkspace
^
in function 'xc'
called on standard input
source to share