Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vim syntax and ftdetect files #2679

Merged
merged 1 commit into from
May 5, 2019

Conversation

laomaiweng
Copy link
Contributor

Hi!

Here are vim syntax and ftdetect files to automatically detect and syntax-highlight firejail profiles in vim.
I built those for myself over the last few days and I feel they are functional enough for a wider audience. :-)

Please note these are my first ever written vim syntax/ftdetect files, so there's likely to be room for improvement. However, they seem to be doing alright with all the profiles I could get my hands on.

Cheers and thanks for making the awesome piece of software that firejail is. :)

@Fred-Barclay Fred-Barclay merged commit a1cc4a5 into netblue30:master May 5, 2019
@Fred-Barclay
Copy link
Collaborator

Awesome! Merged -- thanks. 😄

@laomaiweng laomaiweng deleted the firejail-vim-syntax branch May 6, 2019 12:06
@rusty-snake
Copy link
Collaborator

@laomaiweng as you might see, these file are now installed with --enable-contrib.
I'm not very familiar with vim syntax files that's why I'm asking you how we can adapt the recent dbus changes in the vim syntax.

kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 9, 2023
POSIX tr understands '\n', so use that instead of the less portable
$'\n'.

Commands used to search and replace:

    $ f=contrib/vim/syntax/firejail.vim; \
      printf '%s\n' "$(sed -E \
        "s/tr +\\\$'\\\\n'/tr '\\\\n'/g" "$f")" >"$f"

Added on commit a1cc4a5 ("Add vim syntax and ftdetect files (netblue30#2679)",
2019-05-06).
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 9, 2023
It seems to be equivalent to just delimiting the beginning and the end
of the line with `^foo$`.

Also, put the regex mode (-E) first.

Commands used to search and replace:

    $ f=contrib/vim/syntax/firejail.vim; \
      printf '%s\n' "$(sed -E \
        "s|grep -vEx '([^']+)'|grep -Ev '^\\1\$'|" "$f")" >"$f"

Added on commit a1cc4a5 ("Add vim syntax and ftdetect files (netblue30#2679)",
2019-05-06).
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 9, 2023
Only a single script is passed by argument in each invocation.

Added on commit a1cc4a5 ("Add vim syntax and ftdetect files (netblue30#2679)",
2019-05-06) and on commit d2e10f2 ("vim: update list of syscalls",
2021-05-29) / PR netblue30#4318.
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 9, 2023
To avoid depending on an extra package without need.

Commands used to search and replace:

    $ f=contrib/vim/syntax/firejail.vim; \
      printf '%s\n' "$(sed -E \
        "s|rg -o '([^']+)' -r '\\\$1'|sed -En 's/.*\\1.*/\\\\1/p'|" "$f")" >"$f"

Note: `sed -E` is not in POSIX.1-2017 (Issue 7), but it has been
accepted into the upcoming POSIX standard version[1] and is supported by
at least GNU, busybox and OpenBSD grep.

Added on commit a1cc4a5 ("Add vim syntax and ftdetect files (netblue30#2679)",
2019-05-06).

[1] https://www.austingroupbugs.net/view.php?id=528
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 28, 2023
Having all of syntax files in the same directory makes it easier to
reference all of them at once on a makefile (such as with
`contrib/syntax/files/*.in`).

Also, this makes the path to the gtksourceview language-spec shorter.
Current path/new path:

* contrib/gtksourceview-5/language-specs/firejail-profile.lang
* contrib/syntax/files/firejail-profile.lang

Currently, adding a rule to the root Makefile to generate the
language-spec in the same directory as an input file would take at least
95 characters (with only a single dependency):

    contrib/gtksourceview-5/language-specs/%.lang: contrib/gtksourceview-5/language-specs/%.lang.in

With this commit, the above shortened to 59 characters:

    contrib/syntax/files/%.lang: contrib/syntax/files/%.lang.in

Which should make it more readable.

Relates to netblue30#2679 netblue30#5502.
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 28, 2023
Changes:

* Use the commands from contrib/vim/syntax/firejail.vim to create
  makefile targets to generate syntax lists in contrib/syntax/lists
* Add contrib/syntax/files/example.in as an example of how to generate
  syntax files
* Generate and add the syntax lists, to make it easier to spot if they
  are properly updated when a new command is added or if their recipes
  also need changes
* Add "syntax" and "contrib" makefile targets

Note: The generation commands are executed mostly silently to avoid
generating too much noise when also making other targets.

Note2: In some generation commands, a `$$` escape is used to pass `$` to
the shell, to avoid being interpreted by make as the start of a macro.

Note3: `@make_input@` is used in example.in to make it clear that the
file is generated (and that it is generated by make rather than
configure), similarly to how `@configure_input@` is used in configure
input files.  See also apparmor.vim:

    $ head -n 2 /usr/share/vim/vimfiles/syntax/apparmor.vim
    " generated from apparmor.vim.in by create-apparmor.vim.py
    " do not edit this file - edit apparmor.vim.in or create-apparmor.vim.py instead

Environment: apparmor 3.1.2-1 on Artix Linux.

Relates to netblue30#2679 netblue30#5502 netblue30#5577 netblue30#5612.
kmk3 added a commit to kmk3/firejail that referenced this pull request Jan 28, 2023
Changes:

* Generate firejail.vim from firejail.vim.in
* Generate firejail-profile.lang from firejail-profile.lang.in
* Update the manual syntax file steps on the new command checklist on
  CONTRIBUTING.md to use `make syntax` instead

Relates to netblue30#2679 netblue30#5502 netblue30#5577 netblue30#5612.
kmk3 added a commit to kmk3/firejail that referenced this pull request Jun 10, 2023
Currently it only sets the appropriate filetype for files in
`/etc/firejail` and `~/.config/firejail`.

With this commit, the firejail filetype should also be set when opening
`etc/inc/*.inc`, for example, as long as there is a "firejail" directory
somewhere before that (such as in `/foo/firejail/bar/etc/inc/*.inc`).

Note: At least `*/firejail/*.inc` needs to force the match (by using
`set filetype` rather than `setfiletype`), or else the default vim
checks take precedence (and the filetype for all files in
`etc/inc/*.inc` gets set to `pov`).

Fixes netblue30#4319.

Relates to netblue30#2679.

Co-authored-by: rusty-snake <41237666+rusty-snake@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants