mirror of
https://github.com/CoeJoder/lessfilter-pygmentize.git
synced 2025-11-12 07:03:47 -05:00
Simplify case statement
This commit is contained in:
@@ -13,37 +13,26 @@ for path in "$@"; do
|
||||
pygmentize -f 256 -O style="$PYGMENTIZE_STYLE" "$path"
|
||||
;;
|
||||
*)
|
||||
ext=$([[ "$filename" = *.* ]] && echo ".${filename##*.}" || echo '')
|
||||
case "$ext" in
|
||||
{{ recognized_extensions }})
|
||||
# extension recognized
|
||||
pygmentize -f 256 -O style="$PYGMENTIZE_STYLE" "$path"
|
||||
# attempt to parse the lexer from the shebang if it exists
|
||||
lexer=$(head -n 1 "$path" | grep '^#\!' | awk -F" " \
|
||||
'{ if (/env/) { print $2 } else { sub( /.*\//, ""); print $1;} }')
|
||||
case "$lexer" in
|
||||
node|nodejs)
|
||||
# use `js` lexer for nodejs
|
||||
pygmentize -f 256 -O style="$PYGMENTIZE_STYLE" \
|
||||
-l js "$path"
|
||||
;;
|
||||
"")
|
||||
# fall-back to plain text
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
# unrecognized filename/extension
|
||||
# attempt to parse the lexer from the shebang if it exists
|
||||
lexer=$(head -n 1 "$path" | grep '^#\!' | awk -F" " \
|
||||
'{ if (/env/) { print $2 } else { sub( /.*\//, ""); print $1;} }')
|
||||
case "$lexer" in
|
||||
node|nodejs)
|
||||
# workaround for lack of Node.js lexer alias
|
||||
pygmentize -f 256 -O style="$PYGMENTIZE_STYLE" \
|
||||
-l js "$path"
|
||||
;;
|
||||
"")
|
||||
# fall-back to plain text
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
# use lexer alias parsed from the shebang
|
||||
pygmentize -f 256 -O style="$PYGMENTIZE_STYLE" \
|
||||
-l "$lexer" "$path"
|
||||
;;
|
||||
esac
|
||||
# use lexer alias parsed from the shebang
|
||||
pygmentize -f 256 -O style="$PYGMENTIZE_STYLE" \
|
||||
-l "$lexer" "$path"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
done
|
||||
exit 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user