summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Hall <keith-hall@users.noreply.github.com>2021-05-15 11:33:23 +0300
committerGitHub <noreply@github.com>2021-05-15 11:33:23 +0300
commitbef0bf16542c9e4ac20dae9153e75eeb402b3bc0 (patch)
tree82225de5e0d8b71e7aa4aefd1e58238600f692ef
parent52c11fe23d2d9ed027fae81d2f84de48710ac9ff (diff)
parent8435cad602a92a3c359fb1fb8ce9740d8065a290 (diff)
Merge pull request #1654 from mohamed-abdelnour/support-dash-syntax
Add support for dash shebang
-rw-r--r--CHANGELOG.md1
-rw-r--r--assets/patches/ShellScript.sublime-syntax.patch9
-rw-r--r--tests/syntax-tests/highlighted/dash/shfm425
-rw-r--r--tests/syntax-tests/source/dash/LICENSE.md23
-rw-r--r--tests/syntax-tests/source/dash/shfm425
5 files changed, 881 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 522b1744..61947b3f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@
## Syntaxes
+- Added support for `dash` syntax, see #1654 (@mohamed-abdelnour)
- Added support for `XAML` syntax, see #1590 and #1655 (@mohamed-abdelnour)
diff --git a/assets/patches/ShellScript.sublime-syntax.patch b/assets/patches/ShellScript.sublime-syntax.patch
index 4afcdb00..5aa7fba1 100644
--- a/assets/patches/ShellScript.sublime-syntax.patch
+++ b/assets/patches/ShellScript.sublime-syntax.patch
@@ -1,8 +1,8 @@
diff --git syntaxes/01_Packages/ShellScript/Bash.sublime-syntax syntaxes/01_Packages/ShellScript/Bash.sublime-syntax
-index e973e319..a703cef8 100644
+index e973e319..07c170a7 100644
--- syntaxes/01_Packages/ShellScript/Bash.sublime-syntax
+++ syntaxes/01_Packages/ShellScript/Bash.sublime-syntax
-@@ -30,8 +30,8 @@ file_extensions:
+@@ -30,12 +30,12 @@ file_extensions:
- .zshenv
- .zshrc
- PKGBUILD # https://jlk.fjfi.cvut.cz/arch/manpages/man/PKGBUILD.5
@@ -13,3 +13,8 @@ index e973e319..a703cef8 100644
first_line_match: |
(?x)
+- ^\#! .* \b(bash|zsh|sh|tcsh|ash)\b
++ ^\#! .* \b(bash|zsh|sh|tcsh|ash|dash)\b
+ | ^\# \s* -\*- [^*]* mode: \s* shell-script [^*]* -\*-
+
+ #-------------------------------------------------------------------------------
diff --git a/tests/syntax-tests/highlighted/dash/shfm b/tests/syntax-tests/highlighted/dash/shfm
new file mode 100644
index 00000000..3d382fbb
--- /dev/null
+++ b/tests/syntax-tests/highlighted/dash/shfm
@@ -0,0 +1,425 @@
+#!/usr/bin/env dash
+
+esc() {
+ case $1 in
+ # vt100 (IL is vt102) (DECTCEM is vt520)
+ CUD) printf '%s[%sB' "$esc_c" "$2" ;; # cursor down
+ CUP) printf '%s[%s;%sH' "$esc_c" "$2" "$3" ;; # cursor home
+ CUU) printf '%s[%sA' "$esc_c" "$2" ;; # cursor up
+ DECAWM) printf '%s[?7%s' "$esc_c" "$2" ;; # line wrap
+ DECRC) printf '%s8' "$esc_c" ;; # cursor restore
+ DECSC) printf '%s7' "$esc_c" ;; # cursor save
+ DECSTBM) printf '%s[%s;%sr' "$esc_c" "$2" "$3" ;; # scroll region
+ DECTCEM) printf '%s[?25%s' "$esc_c" "$2" ;; # cursor visible
+ ED[0-2]) printf '%s[%sJ' "$esc_c" "${1#ED}" ;; # clear screen
+ EL[0-2]) printf '%s[%sK' "$esc_c" "${1#EL}" ;; # clear line
+ IL) printf '%s[%sL' "$esc_c" "$2" ;; # insert line
+ SGR) printf '%s[%s;%sm' "$esc_c" "$2" "$3" ;; # colors
+
+ # xterm (since 1988, supported widely)
+ screen_alt) printf '%s[?1049%s' "$esc_c" "$2" ;; # alternate buffer
+ esac
+}
+
+term_setup() {
+ stty=$(stty -g)
+ stty -icanon -echo
+ esc screen_alt h
+ esc DECAWM l
+ esc DECTCEM l
+ esc ED2
+ esc DECSTBM 1 "$((LINES - 2))"
+}
+
+term_reset() {
+ esc DECAWM h >&2
+ esc DECTCEM h >&2
+ esc ED2 >&2
+ esc DECSTBM >&2
+ esc screen_alt l >&2
+ stty "$stty"
+
+ # needed for cd-on-exit
+ printf '%s\n' "$PWD" >&1
+}
+
+term_resize() {
+ # false-positive, behavior intentional, globbing is disabled.
+ # shellcheck disable=2046
+ {
+ set -f
+ set +f -- $(stty size)
+ }
+
+ LINES=$1 COLUMNS=$2
+
+ # space for status_line
+ bottom=$((LINES - 2))
+}
+
+term_scroll_down() {
+ case $((y - $#)) in
+ [0-9]*) return
+ esac
+
+ y=$((y + 1))
+ y2=$((y2 + 1 < bottom ? y2 + 1 : bottom))
+
+ line_print "$((y - 1))" "$@"
+ printf '\n'
+ line_print "$y" "$@"
+ status_line "$#"
+}
+
+term_scroll_up() {
+ case $y in
+ -*|0|1) return
+ esac
+
+ y=$((y - 1))
+
+ line_print "$((y + 1))" "$@"
+
+ case $y2 in
+ 1) esc IL ;;
+ *) esc CUU; y2=$((y2 > 1 ? y2 - 1 : 1))
+ esac
+
+ line_print "$y" "$@"
+ status_line "$#"
+}
+
+cmd_run() {
+ stty "$stty"
+ esc DECTCEM h
+ esc DECSTBM
+ esc ED2
+ "$@" ||:
+ esc DECSTBM 1 "$((LINES - 2))"
+ esc DECTCEM l
+ stty -icanon -echo
+ hist=2
+}
+
+file_escape() {
+ tmp=$1 safe=
+
+ # loop over string char by char
+ while c=${tmp%"${tmp#?}"}; do
+ case $c in
+ '') return ;;
+ [[:cntrl:]]) safe=$safe\? ;;
+ *) safe=$safe$c ;;
+ esac
+
+ tmp=${tmp#?}
+ done
+}
+
+hist_search() {
+ hist=0 j=1
+
+ for file do
+ case ${PWD%%/}/$file in
+ "$old_pwd") y=$j y2=$((j > bottom ? mid : j)) cur=$file
+ esac
+
+ j=$((j + 1))
+ done
+}
+
+list_print() {
+ esc ED2
+ esc CUP
+
+ i=1
+ end=$((bottom + 1))
+ mid=$((bottom / 4 < 5 ? 1 : bottom / 4))
+
+ case $# in
+ 1) [ -e "$1" ] || set -- empty
+ esac
+
+ case $hist in
+ 2) # redraw after cmd run
+ shift "$((y > y2 ? y - y2 : 0))"
+ ;;
+
+ 1) # redraw after go-to-parent
+ hist_search "$@"
+ shift "$((y >= bottom ? y - mid : 0))"
+ ;;
+
+ *) # everything else
+ shift "$((y >= bottom ? y - bottom : 0))"
+ ;;
+ esac
+
+ for file do
+ case $i in
+ "$y2") esc SGR 0 7
+ esac
+
+ case $((i - end)) in
+ -*)
+ line_format "$file"
+ esc CUD
+ ;;
+ esac
+
+ i=$((i + 1))
+ done
+
+ esc CUP "$((y > y2 ? y2 : y))"
+}
+
+redraw() {
+ list_print "$@"
+ status_line "$#"
+}
+
+status_line() {
+ esc DECSC
+ esc CUP "$LINES"
+
+ case $USER in
+ root) esc SGR 31 7 ;;
+ *) esc SGR 34 7 ;;
+ esac
+
+ printf '%*s\r%s ' "$COLUMNS" "" "($y/$1)"
+
+ case $ltype in
+ '') printf %s "$PWD" ;;
+ *) printf %s "$ltype"
+ esac
+
+ esc SGR 0 0
+ esc DECRC
+}
+
+prompt() {
+ esc DECSC
+ esc CUP "$LINES"
+ printf %s "$1"
+ esc DECTCEM h
+ esc EL0
+
+ case $2 in
+ r)
+ stty icanon echo
+ read -r ans ||:
+ stty -icanon -echo
+ ;;
+ esac
+
+ esc DECRC
+ esc DECTCEM l
+ status_line "($y/$#) $PWD"
+}
+
+line_print() {
+ offset=$1
+
+ case $offset in
+