skip to Main Content

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

UPDATE: I changed a bit the function and this one works fine.

function nano() {
if [[ $(type -t code) = "file" ]]; then
    code "$@"
else
    command nano "$@"
fi

}

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search