From a4bcc82a4204aad821d26cdc8f383c7e430b0862 Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Thu, 18 Aug 2022 08:44:25 +0100 Subject: [PATCH] Allow zsh to work with bashrc --- roles/home-cli/files/bashrc | 25 ++++++++++++++++++++++--- roles/home-cli/files/zprofile | 4 ++++ roles/home-cli/files/zshrc | 4 ++++ roles/home-cli/tasks/shell.yml | 8 ++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 roles/home-cli/files/zprofile create mode 100644 roles/home-cli/files/zshrc diff --git a/roles/home-cli/files/bashrc b/roles/home-cli/files/bashrc index 2130628..9105e4e 100644 --- a/roles/home-cli/files/bashrc +++ b/roles/home-cli/files/bashrc @@ -8,6 +8,13 @@ else export ACP="$HOME/data" fi +if [ -n "$ZSH_VERSION" ] +then + # These commands do not exist in zsh. + alias bind=false + alias shopt=false +fi + if [ -f /etc/bashrc ] then . /etc/bashrc @@ -78,7 +85,7 @@ export PAPERSIZE=a4 export POWERSHELL_TELEMETRY_OPTOUT=1 export PYTHONWARNINGS=ignore::UserWarning -if [ "$(uname -s)" == "Darwin" ] +if [ "x$(uname -s)" = "xDarwin" ] then export BASH_SILENCE_DEPRECATION_WARNING=1 fi @@ -100,7 +107,7 @@ else export EDITOR=vi fi -if [ ${XDG_CURRENT_DESKTOP:-unknown} == GNOME ] +if [ ${XDG_CURRENT_DESKTOP:-unknown} = GNOME ] then export QT_FONT_DPI=72 fi @@ -115,6 +122,11 @@ bind 'set completion-ignore-case on' bind 'set enable-bracketed-paste off' export PS1="\[\033[01m\]\u@\h>\[\033[00m\] " +if [ -n "$ZSH_VERSION" ] +then + export PS1="%B%n@%m>%b " +fi + if test $(id -u) -ne 0 && test -x /usr/bin/dnf then alias dnf="dnf --cacheonly --nogpgcheck" @@ -264,7 +276,7 @@ usermotd () { then echo " $(. /etc/os-release; echo $NAME $VERSION)" fi - if [ "x$(uname -s)" == "xDarwin" ] + if [ "x$(uname -s)" = "xDarwin" ] then echo " $(sw_vers -productName) $(sw_vers -productVersion)" fi @@ -309,3 +321,10 @@ case "$-" in *) ;; esac + +if [ -n "$ZSH_VERSION" ] +then + # These commands do not exist in zsh. + unalias shopt + unalias bind +fi diff --git a/roles/home-cli/files/zprofile b/roles/home-cli/files/zprofile new file mode 100644 index 0000000..e655a18 --- /dev/null +++ b/roles/home-cli/files/zprofile @@ -0,0 +1,4 @@ +if [ -e $HOME/.bash_profile ] +then + emulate sh -c ". $HOME/.bash_profile" +fi diff --git a/roles/home-cli/files/zshrc b/roles/home-cli/files/zshrc new file mode 100644 index 0000000..3270014 --- /dev/null +++ b/roles/home-cli/files/zshrc @@ -0,0 +1,4 @@ +if [ -e $HOME/.bashrc ] +then + emulate sh -c ". $HOME/.bashrc" +fi diff --git a/roles/home-cli/tasks/shell.yml b/roles/home-cli/tasks/shell.yml index d2e715c..6a300dd 100644 --- a/roles/home-cli/tasks/shell.yml +++ b/roles/home-cli/tasks/shell.yml @@ -21,3 +21,11 @@ ansible.builtin.copy: src: bash_profile dest: "{{ ansible_env.HOME }}/.bash_profile" +- name: Copy .zshrc + ansible.builtin.copy: + src: zshrc + dest: "{{ ansible_env.HOME }}/.zshrc" +- name: Copy .zprofile + ansible.builtin.copy: + src: zprofile + dest: "{{ ansible_env.HOME }}/.zprofile"