sh 使用Windows上的Git Bash通过命令行打开WebStorm文件。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 使用Windows上的Git Bash通过命令行打开WebStorm文件。相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#
# Opens WebStorm from the command line using Git Bash for Windows.  If you're 
# working within the integrated terminal in WebStorm, this will open the file
# passed in using just the relative path. If the file specified doesn't exist,
# it creates it and opens it.  Just copy wstorm() into wherever you keep your 
# Bash aliases and make sure you change your Terminal path to Git Bash (see 
# Notes section).
#
# ------
# Notes:
# ------
# If you want this to work in WebStorm, you have to change the terminal path in
# Tools > Terminal to the following (quotes included):
# "C:\Program Files\Git\bin\sh.exe" -login -i
# If you have 32-bit Git installed, add " (x86)" to "Program Files".
# FYI, I got this working with version 2016.3.2.
#
# -----------------
# From the website:
# -----------------
# In order to open a file from WebStorm through the command line, the format
# needs to be as follows:
# <WebStorm> <path1> --line <number> <path2>
# where:
# <WebStorm> is the platform-specific product launcher
# <path1> is the path to the project that contains the desired file
# <number> is the number of the line, where the caret should rest
# <path2> is the path to the file to be opened
#
#  www.jetbrains.com/help/webstorm/2016.3/opening-files-from-command-line.html
# -----------------------------------------------------------------------------
wstorm() {
  # Since the WebStorm binary is stored in a folder contingent on the version
  # installed, search for the folder matching "WebStorm" and inject that into
  # the path to the executable.
  ws_root=`ls -1d /c/Program\ Files\ \(x86\)/JetBrains/WebStorm\ * | tail -n1`
  ws_folder="$(basename "$ws_root")"
  ws_exe="C:\\Program Files (x86)\\JetBrains\\$ws_folder\\bin\\webstorm.exe"
  
  wd=$(pwd)
  path_arg="$1"

  if [ $path_arg ]; then
    # If the first three characters are "/c/", then it's a full
    # path.
    hasRoot=$([ ${path_arg:0:3} == "/c/" ] && echo "true" || echo "false")
    
    # If the last character was a slash or dot, it's a directory,
    # otherwise it's a file with a relative path.
    last_path_char=${path_arg: -1}
    if ([ $last_path_char != "/" ] && [ $last_path_char != "." ]); then
      full_path="$wd/$path_arg"
      base_path="$(dirname "$full_path")"

      # Creates the file if it doesn't exist, if you don't want to use this,
      # just comment it out.
      if [ ! -e "$full_path" ]; then
        # If you specify a file in a directory that doesn't exist, create it
        # create the file, and open it.
        if [ ! -d "$base_path" ]; then
          # If you want to create and open a file in a subdirectory of a
          # subdirectory of a subdirectory, go buck wild, this will make it
          # happen!
          mkdir -p $base_path
        fi
        touch $full_path
      fi
      
      "$ws_exe" $wd --line 1 $full_path
    fi

    # If it's a directory, the [line] and [file path] arguments aren't
    # required.
    if [ -d "$1" ]; then
      "$ws_exe" $wd
    fi
  else
    # If no path argument was specified, inform the user and exit:
    echo "Please specify a path or file name."
  fi
}

以上是关于sh 使用Windows上的Git Bash通过命令行打开WebStorm文件。的主要内容,如果未能解决你的问题,请参考以下文章

设置 git bash 以使用 Windows 上的选项卡

Windows 上的 Gcloud 命令(使用 git bash)正在记录错误:WindowsApps/python3:权限被拒绝

Windows XP上的Git sh.exe进程分叉问题,慢吗?

sh Windows上Git Bash的别名

sh Windows上Git Bash的别名

sh Windows上Git Bash的别名