Skip to content

Commit 7dec2c4

Browse files
authored
Merge pull request #133 from thaim/git-switch-default-with-no-argument
run git-switch-default with git switch command
2 parents 456f97c + 55c3785 commit 7dec2c4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

roles/git/tasks/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,22 @@
5656
src: git-switch-default
5757
dest: /usr/local/bin/git-switch-default
5858
mode: '0755'
59+
60+
- name: Set shell info
61+
ansible.builtin.set_fact:
62+
shell_info: "{{ ansible_user_shell | shell_config }}"
63+
64+
- name: Override default command
65+
ansible.builtin.blockinfile:
66+
path: "{{ ansible_user_dir }}/{{ shell_info.rc_file }}"
67+
marker: "# {mark} ANSIBLE MANAGED BLOCK git command"
68+
block: |
69+
git() {
70+
if [ "$1" = "switch" ] && [ $# -eq 1 ]; then
71+
# git switchが引数なしで呼ばれた場合
72+
command git switch-default
73+
else
74+
# 引数がある場合や他のgitサブコマンドはそのまま実行
75+
command git "$@"
76+
fi
77+
}

0 commit comments

Comments
 (0)