From 600732234b4af310b45dab1cea575e04811370a9 Mon Sep 17 00:00:00 2001 From: LinuxSquare <7436714-OfficialLinuxSquare@users.noreply.gitlab.com> Date: Fri, 29 Sep 2023 17:53:55 +0200 Subject: [PATCH] Rework shell --- map.jinja | 4 +-- system/files/shell_commonrc.jinja | 21 --------------- system/files/shell_keybinds | 13 --------- system/files/shell_profile.jinja | 34 +++++++++++++++++++++++ system/shell.sls | 45 +++++-------------------------- 5 files changed, 41 insertions(+), 76 deletions(-) delete mode 100644 system/files/shell_commonrc.jinja delete mode 100644 system/files/shell_keybinds create mode 100644 system/files/shell_profile.jinja diff --git a/map.jinja b/map.jinja index 6dfca76..ebf5e4e 100644 --- a/map.jinja +++ b/map.jinja @@ -1,6 +1,4 @@ {% set noveria = { 'bin_dir': '/usr/local/noveria/bin', - 'app_dir': '/usr/local/noveria/apps', - 'commonrc_dir': '/etc/commonrc.d', - 'zsh_dir': '/etc/zsh.d' + 'app_dir': '/usr/local/noveria/apps' } %} \ No newline at end of file diff --git a/system/files/shell_commonrc.jinja b/system/files/shell_commonrc.jinja deleted file mode 100644 index 5a4a6d1..0000000 --- a/system/files/shell_commonrc.jinja +++ /dev/null @@ -1,21 +0,0 @@ -# This is the global common rc file sourced by all shells. This is not -# something the shells do natively, we just source this file in the appropriate -# places (/etc/bash.bashrc for bash, /etc/.zshrc for zsh). This file is intended -# for basic stuff that works in all shells, like env vars and aliases. -# -# Notes: -# - The code must be able to run in all shells, so keep it simple -# - Keep in mind that what's put in here affects all users on the system - -# add custom bin to PATH variable -export PATH="${PATH}:{{ CUSTOM_BIN }}" - -# source files from {{ COMMONRC_DIR }} -# use ls in a subshell because zsh will warn about an emtpy glob result by -# default. there's a glob flag to avoid that, but that would be zfs specific. -if [ -d {{ COMMONRC_DIR }} ]; then - for i in $(ls {{ COMMONRC_DIR }}/); do - [ -r "{{ COMMONRC_DIR }}/$i" ] && . "{{ COMMONRC_DIR }}/$i" - done - unset i -fi diff --git a/system/files/shell_keybinds b/system/files/shell_keybinds deleted file mode 100644 index 3a56f64..0000000 --- a/system/files/shell_keybinds +++ /dev/null @@ -1,13 +0,0 @@ -# zsh keys configuration -bindkey "^[[H" beginning-of-line -bindkey "^[[F" end-of-line -bindkey "^[[2~" overwrite-mode -bindkey "^[[3~" delete-char -bindkey "^[[A" up-line-or-history -bindkey "^[[B" down-line-or-history -bindkey "^[[D" backward-char -bindkey "^[[C" forward-char -bindkey "^[[1;5D" backward-word -bindkey "^[[1;5C" forward-word -bindkey "^[[5~" beginning-of-buffer-or-history -bindkey "^[[6~" end-of-buffer-or-history diff --git a/system/files/shell_profile.jinja b/system/files/shell_profile.jinja new file mode 100644 index 0000000..e04b425 --- /dev/null +++ b/system/files/shell_profile.jinja @@ -0,0 +1,34 @@ +export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:{{ CUSTOM_BIN }}" + +export PAGER=less +export EDITOR=vim +umask 022 + +# use nicer PS1 for bash and busybox ash +if [ -n "$BASH_VERSION" -o "$BB_ASH_VERSION" ]; then + PS1='\h:\w\$ ' +# use nicer PS1 for zsh +elif [ -n "$ZSH_VERSION" ]; then + PS1='%m:%~%# ' +# set up fallback default PS1 +else + : "${HOSTNAME:=$(hostname)}" + PS1='${HOSTNAME%%.*}:$PWD' + [ "$(id -u)" -eq 0 ] && PS1="${PS1}# " || PS1="${PS1}\$ " +fi + +if [ -n "$BASH_VERSION" ] && [ "$BASH" != "/bin/sh" ]; then + # if we're bash (and not /bin/sh bash), also source the bashrc + # by default, bash sources the bashrc for non-login, + # and only /etc/profile on login (-l). so, make it do both on login. + # this ensures that login-shell bash (e.g. -bash or bash -l) still sources the + # system bashrc, which e.g. loads bash-completion + . /etc/bash/bashrc +fi + +for script in /etc/profile.d/*.sh ; do + if [ -r "$script" ] ; then + . "$script" + fi +done +unset script \ No newline at end of file diff --git a/system/shell.sls b/system/shell.sls index c1fa846..5bdc874 100644 --- a/system/shell.sls +++ b/system/shell.sls @@ -7,25 +7,25 @@ system_shell_pkgs: pkg.installed: - pkgs: - zsh + - alpine-zsh-config - bash - require: - system_base_pkgs -system_shell_commonrc: +system_shell_profile: file.managed: - - name: /etc/commonrc - - source: salt://{{ tpldir }}/files/shell_commonrc.jinja + - name: /etc/profile + - source: salt://{{ tpldir }}/files/shell_profile.jinja - template: jinja - context: CUSTOM_BIN: {{ noveria.bin_dir }} - COMMONRC_DIR: {{ noveria.commonrc_dir }} - user: root - group: root - mode: '0644' - require: - system_shell_pkgs -system_shell_zsh_include_commonrc: +system_shell_zsh_include_profile: file.managed: - name: /etc/.zshrc - source: salt://{{ tpldir }}/files/shell_zshrc.jinja @@ -37,37 +37,4 @@ system_shell_zsh_include_commonrc: - mode: '0644' - makedirs: false - require: - - system_shell_commonrc - -system_shell_zsh_zshenv: - file.managed: - - name: /etc/.zshenv - - source: salt://{{ tpldir }}/files/shell_zshenv.jinja - - template: jinja - - user: root - - group: root - - mode: '0644' - - makedirs: false - - require: - - system_shell_commonrc - -system_shell_zshd_directory: - file.directory: - - name: {{ noveria.zsh_dir }} - - user: root - - group: root - - dir_mode: '0755' - - file_mode: '0644' - - makedirs: true - - require: - - system_shell_pkgs - -system_shell_zsh_keybinds: - file.managed: - - name: {{ noveria.zsh_dir }}/00-keybinds - - source: salt://{{ tpldir }}/files/shell_keybinds - - user: root - - group: root - - mode: '0644' - - require: - - system_shell_zshd_directory + - system_shell_profile