Skip to content

Commit

Permalink
Simple shell script support
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewRadev committed Sep 2, 2017
1 parent 1f23633 commit 2d5cd2b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
5 changes: 3 additions & 2 deletions autoload/sideways/parsing.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function! sideways#parsing#Parse(definitions)
let start_pattern = definition.start
let end_pattern = definition.end
let delimited_by_whitespace = get(definition, 'delimited_by_whitespace', 0)
let single_line = get(definition, 'single_line', 0)

if delimited_by_whitespace
let delimiter_pattern = '\s\+'
Expand Down Expand Up @@ -81,7 +82,7 @@ function! sideways#parsing#Parse(definitions)
" bracket check
call s:PushItem(items, current_item, col('$') - 1)

if delimited_by_whitespace
if delimited_by_whitespace && !single_line
" there should be something on the next line, keep going
normal! l
call s:SkipWhitespace()
Expand All @@ -104,7 +105,7 @@ function! sideways#parsing#Parse(definitions)
call s:PushItem(items, current_item, col('$') - 1)
let current_item = s:NewItem()

if delimited_by_whitespace
if delimited_by_whitespace && !single_line
" try to continue after the end of this line
normal! l
call s:SkipWhitespace()
Expand Down
11 changes: 11 additions & 0 deletions plugin/sideways.vim
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ autocmd FileType cucumber let b:sideways_definitions = [
\ },
\ ]

autocmd FileType sh let b:sideways_definitions = [
\ {
\ 'skip_syntax': ['shDoubleQuote', 'shSingleQuote', 'shComment'],
\ 'start': '\%(^\|[|(`]\)\s*\k\{1,} \ze\s*[^=]',
\ 'end': '\s*\%(|\|\_$\)',
\ 'brackets': ['([{''"', ')]}''"'],
\ 'single_line': 1,
\ 'delimited_by_whitespace': 1,
\ },
\ ]

command! SidewaysLeft call sideways#MoveLeft() | silent! call repeat#set("\<Plug>SidewaysLeft")
command! SidewaysRight call sideways#MoveRight() | silent! call repeat#set("\<Plug>SidewaysRight")

Expand Down
29 changes: 29 additions & 0 deletions spec/plugin/sh_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'spec_helper'

describe "shell scripts" do
let(:filename) { 'test.sh' }

specify "simple case" do
set_file_contents <<-EOF
command subcommand --one --two=three -- filename | vim - -R
EOF

vim.search('subcommand')
vim.right
assert_file_contents <<-EOF
command --one subcommand --two=three -- filename | vim - -R
EOF

vim.search('subcommand')
vim.left
assert_file_contents <<-EOF
command subcommand --one --two=three -- filename | vim - -R
EOF

vim.search('subcommand')
vim.left
assert_file_contents <<-EOF
command filename --one --two=three -- subcommand | vim - -R
EOF
end
end

0 comments on commit 2d5cd2b

Please sign in to comment.