diff --git a/README.md b/README.md index 9b7d959..19f8272 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ansible Role: powerline -An Ansible role that installs powerline on Ubuntu. +An Ansible role that installs powerline on Linux. ## Requirements diff --git a/Vagrantfile b/Vagrantfile index 422cba7..c4e6230 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,15 +1,20 @@ Vagrant.configure('2') do |config| - config.vm.box = 'ubuntu/trusty64' + config.vm.box = 'fgrehm/trusty64-lxc' config.vm.synced_folder '.', '/vagrant', disabled: true config.vm.synced_folder '.', '/vagrant/ansible-role-powerline' - config.vm.provider 'lxc' do |lxc, override| - override.vm.box = 'fgrehm/trusty64-lxc' - end - config.vm.provision 'shell' do |s| s.keep_color = true s.path = 'tests/init.sh' end + + config.vm.define 'ubuntu-trusty' do |vmconfig| + vmconfig.vm.hostname = 'ansible-role-powerline-ubuntu-trusty64' + end + + config.vm.define 'fedora-23' do |vmconfig| + vmconfig.vm.hostname = 'ansible-role-powerline-fedora-23' + vmconfig.vm.box = 'obnox/fedora23-64-lxc' + end end diff --git a/meta/main.yml b/meta/main.yml index 01fa211..0f0a5a4 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,13 +1,16 @@ --- galaxy_info: author: mjanser - description: Powerline on Ubuntu + description: Installs powerline on Linux distributions license: MIT min_ansible_version: 1.6 platforms: - name: Ubuntu versions: - trusty + - name: Fedora + versions: + - 23 categories: - system dependencies: [] diff --git a/tasks/install-dnf.yml b/tasks/install-dnf.yml new file mode 100644 index 0000000..eb3ed07 --- /dev/null +++ b/tasks/install-dnf.yml @@ -0,0 +1,11 @@ +--- +- name: "include variables for dnf installation of powerline" + include_vars: dnf.yml + +- name: "ensure packages for powerline are installed" + dnf: + name: "{{ item }}" + with_items: + - powerline + - powerline-docs + sudo: yes diff --git a/tasks/install-pip.yml b/tasks/install-pip.yml new file mode 100644 index 0000000..84c9f63 --- /dev/null +++ b/tasks/install-pip.yml @@ -0,0 +1,17 @@ +--- +- name: "include variables for pip installation of powerline" + include_vars: pip.yml + +- name: "ensure python pip is installed" + apt: + name: "{{ item }}" + with_items: + - git + - python-pip + sudo: yes + when: ansible_pkg_mgr == 'apt' + +- name: "ensure powerline is installed" + pip: + name: powerline-status + sudo: yes diff --git a/tasks/main.yml b/tasks/main.yml index 3bd7750..316ede0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,29 +1,19 @@ --- -- name: "ensure python pip is installed" - apt: - name: "{{ item }}" - with_items: - - git - - python-pip - sudo: yes +- include: install-dnf.yml + when: "ansible_os_family == 'RedHat'" -- name: "ensure powerline is installed" - pip: - name: powerline-status - sudo: yes +- include: install-pip.yml + when: "ansible_os_family != 'RedHat'" -- name: "ensure powerline is loaded in bashrc" - copy: - src: powerline.sh - dest: /etc/profile.d/ - owner: root - group: root - mode: 0644 +- name: "ensure powerline is loaded in shell" + template: + src: powerline.sh.j2 + dest: /etc/profile.d/powerline.sh sudo: yes - name: "ensure default top theme for powerline is configured" lineinfile: - dest: /usr/local/lib/python2.7/dist-packages/powerline/config_files/config.json + dest: "{{ powerline_config_file }}" line: "\t\t\"default_top_theme\": \"{{ powerline_default_top_theme }}\"," regexp: "default_top_theme" insertbefore: "term_truecolor" @@ -32,5 +22,11 @@ - name: "ensure powerline for shell is configured" template: src: powerline-shell.json.j2 - dest: /usr/local/lib/python2.7/dist-packages/powerline/config_files/themes/shell/default.json + dest: "{{ powerline_themes_directory }}/shell/default.json" + sudo: yes + +- name: "ensure powerline for tmux is configured" + template: + src: powerline-tmux.json.j2 + dest: "{{ powerline_themes_directory }}/tmux/default.json" sudo: yes diff --git a/templates/powerline-shell.json.j2 b/templates/powerline-shell.json.j2 index e27948c..3340dde 100644 --- a/templates/powerline-shell.json.j2 +++ b/templates/powerline-shell.json.j2 @@ -1,6 +1,9 @@ { "segments": { "left": [ + { + "function": "powerline.segments.shell.mode" + }, { "function": "powerline.segments.common.net.hostname", "priority": 10 @@ -16,6 +19,10 @@ { "function": "powerline.segments.shell.cwd", "priority": 10 + }, + { + "function": "powerline.segments.shell.jobnum", + "priority": 20 }{% if powerline_shell_vcs_branch %}, { "function": "powerline.segments.common.vcs.branch", @@ -23,5 +30,12 @@ } {% endif %} ] + }, + "segment_data": { + "branch": { + "args": { + "status_colors": true + } + } } } diff --git a/templates/powerline-tmux.json.j2 b/templates/powerline-tmux.json.j2 new file mode 100644 index 0000000..d3463ef --- /dev/null +++ b/templates/powerline-tmux.json.j2 @@ -0,0 +1,10 @@ +{ + "segments": { + "right": [ + { + "function": "powerline.segments.common.sys.system_load", + "priority": 50 + } + ] + } +} diff --git a/files/powerline.sh b/templates/powerline.sh.j2 similarity index 60% rename from files/powerline.sh rename to templates/powerline.sh.j2 index c12797b..464fae4 100644 --- a/files/powerline.sh +++ b/templates/powerline.sh.j2 @@ -2,5 +2,5 @@ if [ -f `which powerline-daemon` ]; then powerline-daemon -q POWERLINE_BASH_CONTINUATION=1 POWERLINE_BASH_SELECT=1 - . /usr/local/lib/python2.7/dist-packages/powerline/bindings/bash/powerline.sh + . {{ powerline_bindings_directory }}/bash/powerline.sh fi diff --git a/tests/init.sh b/tests/init.sh index fd03eba..85e146c 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -4,15 +4,20 @@ export PYTHONUNBUFFERED=1 export ANSIBLE_FORCE_COLOR=1 export DEBIAN_FRONTEND=noninteractive -if ! which ansible >/dev/null; then - echo "Add APT repository" - apt-get install -qq software-properties-common &> /dev/null || exit 1 - apt-add-repository ppa:ansible/ansible &> /dev/null || exit 1 - - apt-get update -qq - - echo "Installing Ansible" - apt-get install -qq python-mysqldb ansible &> /dev/null || exit 1 +if ! which ansible &>/dev/null; then + if which dnf &>/dev/null; then + echo "Installing Ansible" + dnf install -q -y ansible python-dnf >/dev/null || exit 1 + else + echo "Add APT repository" + apt-get install -qq software-properties-common >/dev/null || exit 1 + apt-add-repository ppa:ansible/ansible >/dev/null || exit 1 + + apt-get update -qq >/dev/null + + echo "Installing Ansible" + apt-get install -qq ansible >/dev/null || exit 1 + fi fi diff --git a/vars/dnf.yml b/vars/dnf.yml new file mode 100644 index 0000000..0088336 --- /dev/null +++ b/vars/dnf.yml @@ -0,0 +1,4 @@ +--- +powerline_config_file: /etc/xdg/powerline/config.json +powerline_themes_directory: /etc/xdg/powerline/themes +powerline_bindings_directory: /usr/share/powerline diff --git a/vars/pip.yml b/vars/pip.yml new file mode 100644 index 0000000..5ccd2cd --- /dev/null +++ b/vars/pip.yml @@ -0,0 +1,4 @@ +--- +powerline_config_file: /usr/local/lib/python2.7/dist-packages/powerline/config_files/config.json +powerline_themes_directory: /usr/local/lib/python2.7/dist-packages/powerline/config_files/themes +powerline_bindings_directory: /usr/local/lib/python2.7/dist-packages/powerline/bindings