Code Monkey home page Code Monkey logo

sublime-fish's Introduction

Friendly Interactive Shell (fish)

A Sublime Text package for the friendly interactive shell. It features a robust syntax highlighting scheme that mimics the native highlighting behaviour of fish.

The package currently supports up to fish version: 3.7

Note: ST3 support will cease in a future release. ST2 support is capped at fish 2.7 with a limited set of the following features.

Features

  • Snippets for common constructs.
  • Extensive syntax highlighting:
  • Indent and prettify: Reformat the active file with fish_indent:
    • Use ctrl+alt+i or your build system shortcut (eg, ctrl+b).
    • Optional setting to run automatically when file is saved.

Installation

Via Package Control

Install Package Control, then go to Command Palette (Ctrl+Shift+P) > Package Control: Install Package > fish.

Manual

Clone the repository to your Packages directory and rename it to fish.

cd /path/to/sublime/packages/directory
git clone https://github.com/Phidica/sublime-fish.git
mv sublime-fish fish

Open a .fish file and verify the selected syntax is "Fish".

Screenshots

As of release 3.0.0, a fish script (for example, fish-shell/share/functions/ls.fish) will look something like:

Screenshot of text in Monokai

Figure 1: Default Monokai colour scheme

Screenshot of text in custom Monokai

Figure 2: Example custom Monokai colour scheme formatting additional scopes

Exposed scopes

fish construct Scope name
Unquoted string meta.string.unquoted
Command name meta.function-call.name
Parameters meta.function-call.parameter.option/argument
File path (in argument) meta.function-call.parameter.argument.path
File path (in redirection) meta.function-call.operator.redirection.path
Redirection meta.function-call.operator.redirection.{stdin,stdout,stderr}.{explicit,implicit} and keyword.operator.redirect.{truncate,append}
Job expansion meta.function-call.parameter.argument.job-expansion and punctuation.definition.job
Process expansion meta.function-call.parameter.argument.process-expansion and punctuation.definition.process
Variable expansion meta.variable-expansion and punctuation.definition.variable
Command substitution meta.parens.command-substitution and punctuation.section.parens.begin/end
Index expansion meta.brackets.index-expansion and punctuation.section.brackets.begin/end
Brace expansion meta.braces.brace-expansion and punctuation.section.braces.begin/separator/end
Wildcard expansion meta.wildcard-expansion and keyword.operator.question-mark/single-star/double-star
Home directory expansion keyword.operator.tilde

Branches and releases

Support for different ST major versions is separated between several branches:

  • master: Plugins compatible with ST4, and syntax provides highlighting for fish versions 2.7 and up.
  • st3: Plugins compatible with ST3 and above (via backwards compatibility features), and syntax provides highlighting for fish versions 2.7 and up.
  • st2: Plugins only compatible with ST2, syntax uses the more limited tmLanguage scheme instead of sublime-syntax, and provides highlighting for fish 2.7 only.

The particular fish major version supported by a tagged release is indicated by the version number:

  • The 2.x.x series (on st2 and st3) only supports fish 2.7.
  • The 3.x.x series (on st3 and master) includes support for fish 3.0 and beyond.

Contribution

Requirements:

  • PackageDev, only for ST2 development and changing the tmPreferences file.

ST2 development: The source file of the syntax is fish.YAML-tmLanguage. When editing this file, "compile" it with the PackageDev build system to automatically generate the fish.tmLanguage file which is used by Sublime Text 2.

ST3+ development: The source file of the syntax is fish.sublime-syntax.

Guide for contributing is located here.

History

The first Sublime Text fish syntax highlighter was by toru hamaguchi. When that project became unmaintained, @Phidica fully rewrote the schema and replaced the links on Package Control.

sublime-fish's People

Contributors

eugenesvk avatar nhooyr avatar phidica avatar toru-hamaguchi avatar weakish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

saqua eugenesvk

sublime-fish's Issues

Highlight issue

The following code results the last end being highlighted the full width of the document:

function my_func
  begin
    echo "hi"
  end; or begin
    echo "hi again"
  end
end

screen shot 2017-08-14 at 16 09 27

snippets don't respect tab size and "translate to spaces" settings

In the snippet files, all snippets that apply an indentation indent with 2 spaces. If you use a tab character for the indent, Sublime will automatically translate that to 4 spaces, or tabs, or whatever. Right now I have my settings set to 4 spaces + translate tabs to spaces, but inserting a snippet gives me a 2 space indent.

Also it's probably a good idea to organize those snippet files in a subfolder snippets.

Stderr redirect append operator `^^` and deprecation warnings

I found that the stderr redirect append operator ^^ (which is like >> but for redirecting stderr instead of stdout) gets a deprecation message suggesting you replace it with 2>, but I believe that since this is an append operator, 2>> would be the appropriate replacement.

The current behavior is misleading and can lead to people accidentally introducing changes in the logic of their fish scripts.

Thanks so much for maintaining this awesome package! It's super useful!

Lines with pipelines and comments inside functions or begin-end blocks mess up `end` highlighting

It seems to be the case that end doesn't end up correctly highlighted in function/begin/etc blocks when the block's final line that isn't just a comment is a pipeline ending with a comment. I gave a bunch of examples below to show when this does and doesn't trigger.


Screen Shot 2019-11-21 at 8 31 40 PM

And the text from the screenshot:

# Example 1
begin
    cat file.txt # print file.txt
end

# Example 2
begin
    cat file.txt # print file.txt
    # comment
end

# Example 3
begin
    cat file.txt | grep 'word' # Find `word` in file.txt
end

# Example 4
begin
    cat file.txt | grep 'word' # Find `word` in file.txt

end

# Example 5
begin
    cat file.txt | grep 'word' # Find `word` in file.txt
    echo "hello world"
end


# Example 6
begin
    cat file.txt | grep 'word'
    # Find `word` in file.txt
end

# Example 7
begin
    cat file.txt | grep 'word' # Find `word` in file.txt
    # comment
end

Highlight options/switches for commands

I'd like to see

foo -a -b --a-long-option
#   ^ should be punctuation.definition.parameter
#   ^^ should be variable.parameter
#      ^ should be punctuation.definition.parameter
#      ^^ should be variable.parameter
#         ^^ should be punctuation.definition.parameter
#         ^^^^^^^^^^^^^^^ should be variable.parameter

Sporadic integer highlighting

complete -c node -l  es52_globals -d 'activate new semantics for global var declarations. type: bool default: false'
#                       ^ should this be a constant.numeric?

got hang up problem

sublime will often hang up when using this package to write fish codes.

hang up which means CPU's usage is 100% then not responding, I have to kill the sublime process to force quit.

for example, following codes will make my sublime hang up:

function crash

  # going to rewrite it to fish code
  function name {
    help_message="help message, usage example: name"
    if [[ $# -eq 0 ]]; then
      echo $help_message
    else
      code=$1
      if [ "$code" == '--help' ]; then
        echo $help_message
      else
        echo "param: $code"
      fi
    fi
  }

end

my sublime version is v2.0.2

Any idea?

"end" at the end of file is not highlighted correctly

Consider the code

if true
end

(without a newline after end). Then end is highlighted as if it were a command name rather than a keyword; in Monokai, blue instead of red.

In other syntax highlighters (try the same code highlighted like MATLAB), this behaves as expected.

Some weirdness with equals signs

#!/usr/local/bin/fish
set equals =
echo "$equals"
# <- missing variable.function

I am absolutely loving the new variable.parameter scopes :)

Prevent error message if no valid fish binary available

This error message shows up when starting Sublime with a fish file loaded.

---------------------------
Sublime Text
---------------------------
Error: Couldn't find fish_indent executable. Specify a nonstandard install location in Preferences > Package Settings > Fish > Settings.
---------------------------
OK   
---------------------------

I'm on Windows and only have fish installed in WSL, so I can't specify a fish install ๐Ÿ˜ข
I think it'd be nice to get an option to disable this message or explicitly disable auto-indenting, as I'd still love to have the syntax highlighting from this package.

bourne-style test commands not recognized

#!/usr/bin/env fish
function die
    echo $argv
    exit 1 
end
set tokens foo bar
[ (count $tokens) -eq 3 ] ; or die whoops
# <- should ideally be support.function.test.begin
#                       ^ should ideally be support.function.test.end

Various highlighting issues

This looks very good, thanks for this! There are a few issues with it though.

https://www.sublimetext.com/docs/3/scope_naming.html


echo $$v[1][2]
#       ^ should be punctuation.section.brackets.begin
#         ^ should be punctuation.section.brackets.end
#          ^ should be punctuation.section.brackets.begin
#            ^ should be punctuation.section.brackets.begin

foobar
# ^^^^ variable.function, not support.function

foo -a -b --a-long-option
#   ^ should be punctuation.definition.parameter
#   ^^ should be variable.parameter
#      ^ should be punctuation.definition.parameter
#      ^^ should be variable.parameter
#         ^^ should be punctuation.definition.parameter
#         ^^^^^^^^^^^^^^^ should be variable.parameter

ls \
#  ^ should be punctuation.separator.continuation
-a

foo\
bar
#^^ still part of foo, this reads "invoke the command foobar"

function show --no-scope-shadowing
    #         ^^^^^^^^^^^^^^^^^^^^ variable.parameter
    ls
end

for i in $PATH; echo $i is in the path; end
#             ^ should be keyword.operator
#                                     ^ should be keyword.operator

echo $FOO
#     ^^^ variable.other.readwrite ?


echo hello > output.txt
#          ^ should be keyword.operator
cat < output.txt
#   ^ shoul be keyword.operator

echo Hello > all_output.txt ^&1
#                           ^ should be keyword.operator ("redirect stderr to")
#                            ^^ ("filedescriptor 1 aka stdout")

cat foo.txt | head
#           ^ keyword.operator
#             ^^^^ excellent!

make fish 2>| less
#         ^^^ pipe stderr to stdin of "less"
emacs &
#     ^ keyword.operator ("do this in the background")

You could consider copying my bash rewrite here and adjusting the function and parameter syntax accordingly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.