Skip to content

Commit

Permalink
Merge pull request #4 from fubarhouse/issue-3
Browse files Browse the repository at this point in the history
PR for #3
  • Loading branch information
fubarhouse authored Apr 26, 2017
2 parents 5b4e98a + f14e03d commit 486e323
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Install [Dockutil](https://github.com/kcrawford/dockutil) and remove, add and an

## Role Variables

### Removal of dock items

Dock items to remove:

````
Expand All @@ -32,12 +34,17 @@ dockitems_disabled:
- Terminal
````

Or, if you want to remove all dock items, use:

#### Remove all: Preferred method
```
dockitems_remove_all: true
```
#### Remove all: Alternative method:
````
dockitems_disabled:
- all
```
````

### Adding dock items

Dock items to add, including name, path and weight/position:

Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# To manage dock items.
#

dockitems_remove_all: false

dockitems_disabled:
- Launchpad
- Mail
Expand Down
61 changes: 51 additions & 10 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,61 @@
- name: Dockutil | Ensure installed.
homebrew:
name: "dockutil"
state: present
state: installed

- name: Dockutil | Remove all unwanted dock items
shell: dockutil --remove "{{ item }}"
ignore_errors: true
- name: Dockutil | Get information on items to remove
shell: "dockutil --find '{{ item }}'"
register: dockutil_removeditems
with_items: "{{ dockitems_disabled }}"
when: "{{ dockitems_disabled | length > 0 }}"
changed_when: false
failed_when: false
when: dockitems_remove_all|bool == false

- name: Dockutil | Remove all dock items
shell: "dockutil --remove all --no-restart"
register: removed_items_task
when: dockitems_remove_all|bool == true

- name: Dockutil | Remove all unwanted dock items
shell: "dockutil --remove '{{ item.item }}' --no-restart"
register: removed_items_task
with_items: "{{ dockutil_removeditems.results }}"
when:
- dockitems_remove_all|bool == false
- '"{{ item.item }} was found in persistent-apps" in item.stdout'

- name: Dockutil | Get information on configured setup
shell: "dockutil --find '{{ item.name }}'"
register: dockutil_newdata
with_items: "{{ dockitems_enabled }}"
changed_when: false
failed_when: false

- name: Dockutil | Adding items
shell: dockutil --find "{{ item.name }}" || dockutil --add "{{ item.path }}"
shell: "dockutil --add '{{ item.item.path }}' --position {{ item.item.pos }} --no-restart"
register: added_items_task
with_items: "{{ dockutil_newdata.results }}"
when: '"{{ item.item.name }} was not found in" in item.stdout'

- name: Dockutil | Get information on current setup
shell: "dockutil --find '{{ item.name }}'"
register: dockutil_currdata
with_items: "{{ dockitems_enabled }}"
when: "{{ dockitems_enabled | length > 0 }}"
changed_when: false
failed_when: false

- name: Dockutil | Moving items
shell: dockutil --move "{{ item.name }}" --position "{{ item.pos }}"
with_items: "{{ dockitems_enabled }}"
when: "{{ dockitems_enabled | length > 0 }}"
shell: "dockutil --move '{{ item.item.name }}' --position {{ item.item.pos }} --no-restart"
register: moved_items_task
with_items: "{{ dockutil_currdata.results }}"
when:
- '"{{ item.item.name }} was found in persistent-apps at slot {{ item.item.pos }} in" not in item.stdout'
- '"{{ item.item.name }} was not found" not in item.stdout'

- name: Dockutil | Restart Dock
shell: "/usr/bin/killall Dock"
changed_when: false
when: >
removed_items_task.changed|bool == true or
moved_items_task.changed|bool == true or
added_items_task.changed|bool == true

0 comments on commit 486e323

Please sign in to comment.