From 2ff533c9a91701f5eeac38d69eeccad38f79ba52 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Tue, 19 Nov 2024 16:14:29 +0100 Subject: [PATCH] Fix nanorc errors --- README.md | 6 +++--- tasks/main.yml | 24 ++++++++++++++++++++++++ templates/etc/nanorc.j2 | 4 ++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3b7409b..fc0a0bf 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,10 @@ Set up nano in Debian-like systems. * `nano_nanorc_destinations.key.mode`: The mode of the file, such as 0644 (optional, default `0644`) * `nano_tabsize`: [default: `2`]: Tab size -* `nano_tabstospaces`: [default: `true`]: Whether or not to convert typed tabs to spaces -* `nano_smooth_scrolling`: [default: `true`]: Whether or not to use smooth scrolling +* `nano_tabstospaces`: [default: `true`]: Whether to convert typed tabs to spaces +* `nano_smooth_scrolling`: [default: `true`]: Whether to use smooth scrolling (version `< 5.6.1`) -* `nano_improved_nanorc_install`: [default: `true`]: Whether or not to install [improved syntax highlighting](https://github.com/nanorc/nanorc) +* `nano_improved_nanorc_install`: [default: `true`]: Whether to install [improved syntax highlighting](https://github.com/nanorc/nanorc) * `nano_improved_nanorc_langs`: [default: `all`]: Languages to enable after installation * `nano_improved_nanorc_git_repo`: [default: `https://github.com/nanorc/nanorc`]: The repository url * `nano_improved_nanorc_git_branch`: [default: `master`]: The branch to checkout diff --git a/tasks/main.yml b/tasks/main.yml index 91c8992..ec225dc 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,6 +11,30 @@ - nano - nano-install +- name: get (current) version # noqa risky-shell-pipe + ansible.builtin.shell: > + nano --version 2>&1 | head -1 | awk '{print $NF}' + register: _get_current_version + changed_when: false + check_mode: false + failed_when: "_get_current_version.rc != 0" + tags: + - configuration + - nano + - nano-version + - nano-version-get + +- name: set (current) version + ansible.builtin.set_fact: + nano_version: "{{ _get_current_version.stdout | regex_search('^([0-9]+\\.[0-9]+\\.?[0-9]*)$') }}" + changed_when: false + check_mode: false + tags: + - configuration + - nano + - nano-version + - nano-version-set + - name: install improved nanorc ansible.builtin.import_tasks: install-improved-nanorc.yml when: nano_improved_nanorc_install | bool diff --git a/templates/etc/nanorc.j2 b/templates/etc/nanorc.j2 index b96bb45..ca100f7 100644 --- a/templates/etc/nanorc.j2 +++ b/templates/etc/nanorc.j2 @@ -140,20 +140,24 @@ set nowrap ## beginning of the line. # set smarthome +{% if nano_version is version('5.6.1', '<') %} ## Use smooth scrolling as the default. {% if nano_smooth_scrolling %} set smooth {% else %} # set smooth {% endif %} +{% endif %} ## Use this spelling checker instead of the internal one. This option ## does not properly have a default value. ## # set speller "aspell -x -c" +{% if nano_version is version('6.3', '<') %} ## Allow nano to be suspended. set suspend +{% endif %} ## Use this tab size instead of the default; it must be greater than 0. {% if nano_tabsize %}