Windows equivalent of the Mac OS X “open” command

前端 未结 9 1344
轮回少年
轮回少年 2021-02-05 08:25

Liu Chang asked a very similar question to this one here, Linux equivalent of the Mac OS X "open" command.

Is there a windows equivalent for the Mac OS X \"ope

9条回答
  •  臣服心动
    2021-02-05 09:06

    If you use cygwin (or git bash), here's a quick script hack. Change the EDITOR to be whatever you want:

    #!/bin/sh
    # open
    
    EDITOR="exec subl.exe"
    BROWSER="/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"
    
    if [ -d "$1" ]; then
        exec explorer.exe $(cygpath -w "$1")
    elif [ -f "$1" ]; then
        path=$(cygpath --windows "$1")
        case "$1" in
        *.xml) $EDITOR "$1";;
        *.txt) $EDITOR "$1";;
        *.html) "$BROWSER" "$path";;
        file://*) "$BROWSER" "$path";;
        http://*) "$BROWSER" "$path";;
        https://*) "$BROWSER" "$path";;
        esac
    else
        # TODO non-existent file/dir
        echo "non existent file: $1"
        exit 1
    fi
    
    exit 0
    

提交回复
热议问题