I would like replace the nano command when I am using a Terminal Session with remote ssh in Visual Studio Code.
Why I need it? Using different linux server not always I have the code editor available and I am live little frustating mitstakes: I often write nano when code is available and sometimes I write code in putty.
I would like a special "nano" command / function: if code is available then execute code else execute nano end if
Of course other way are accepted.
thanks
CodePudding user response:
Maybe the way to do that you want is create a "alias" in the bashrc file of the system.
alias nano='command to open vscode'
To open VSCode insteand of Nano if it is installed, this alias has to be created into a if statement.
if [ <check if installed> ]
then
<alias to open vscode>
fi
If vscode is not installed default nano will open. But, if you use different Linux Systems you need to do this configuration at each of them.
CodePudding user response:
Assuming VSCode is installed at /usr/bin/code, try this :
nano(){
local cmd=/usr/bin/code
if test -x "$cmd"; then
"$cmd" "$@"
else
command nano "$@"
fi
}