diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000..256d0e6 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1 @@ +external-sources=true \ No newline at end of file diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..7e257db --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": [] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/fonts/MesloLGS-NF.sh b/fonts/MesloLGS-NF.sh new file mode 100755 index 0000000..4c1386b --- /dev/null +++ b/fonts/MesloLGS-NF.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +echo 'Installing Meslo Nerd Font' +font_dir="/usr/local/share/fonts/ttf/MesloLGS-NF" +mkdir --parents "${font_dir}" + +if [ ! -f "${font_dir}/MesloLGS NF Regular.ttf" ]; then + echo $'\t| Installing MesloLGS NF Regular...' + curl --silent --location --output "${font_dir}/MesloLGS NF Regular.ttf" https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf +else + echo $'\t| Already MesloLGS NF Regular installed' +fi +if [ ! -f "${font_dir}/MesloLGS NF Bold.ttf" ]; then + echo $'\t| Installing MesloLGS NF Bold...' + curl --silent --location --output "${font_dir}/MesloLGS NF Bold.ttf" https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf +else + echo $'\t| Already MesloLGS NF Bold installed' +fi +if [ ! -f "${font_dir}/MesloLGS NF Italic.ttf" ]; then + echo $'\t| Installing MesloLGS NF Italic...' + curl --silent --location --output "${font_dir}/MesloLGS NF Italic.ttf" https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf +else + echo $'\t| Already MesloLGS NF Italic installed' +fi +if [ ! -f "${font_dir}/MesloLGS NF Bold Italic.ttf" ]; then + echo $'\t| Installing MesloLGS NF Bold Italic...' + curl --silent --location --output "${font_dir}/MesloLGS NF Bold Italic.ttf" https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf +else + echo $'\t| Already MesloLGS NF Bold Italic installed' +fi +echo $'\t| Rebuilding font cache...' +fc-cache diff --git a/packages/jq/bash.sh b/packages/jq/bash.sh new file mode 100644 index 0000000..f1f641a --- /dev/null +++ b/packages/jq/bash.sh @@ -0,0 +1 @@ +#!/usr/bin/env bash diff --git a/packages/zsh/bash.sh b/packages/zsh/bash.sh new file mode 100644 index 0000000..3f3a593 --- /dev/null +++ b/packages/zsh/bash.sh @@ -0,0 +1,35 @@ +#!/bin/env bash +set -eu -o pipefail + +tabs 2 + +user=${1:--1} +userId="$(id -u "${user}" 2>/dev/null || echo -1)" + +[[ "${user}" == -1 ]] && { + echo "No user was specified." + exit 1 +} + +[[ "${userId}" == -1 ]] && { + echo "Specified user does not exist." + exit 1 +} + +[ -f "/etc/os-release" ] && source /etc/os-release +source "./utils/pkg.sh" + +if [[ "${ID}" == "opensuse-microos" ]]; then + pkg install zsh + + ./fonts/MesloLGS-NF.sh + + echo 'Installing global zshrc' + # shellcheck disable=SC2002 + cat 'zsh/globalrc.zsh' | sudo tee /etc/zsh.zshrc.local 1>/dev/nul + + echo 'Creating Konsole profile with font enable' + echo 'Enable font for vscode' +fi + +tabs -0 diff --git a/packages/zsh/globalrc.zsh b/packages/zsh/globalrc.zsh new file mode 100644 index 0000000..28cd49a --- /dev/null +++ b/packages/zsh/globalrc.zsh @@ -0,0 +1,114 @@ +throw() { + echo $@ + exit 2 +} + + + +ZSH_PLUGIN_DIR="/etc/zsh_plugin.d" + +if [ ! -d "${ZSH_PLUGIN_DIR}" ]; then + echo "ZSH plugin directory does not exists; creating." + mkdir "${ZSH_PLUGIN_DIR}" +fi + + +download() { + pluginName=$1 + url=$2 + [[ ! -n "$pluginName" || ! -n "$url" ]] && throw "Missing 1 or more arguments." + + mkdir -p "${ZSH_PLUGIN_DIR}/${pluginName}" + + curl -s "${url}" \ + | grep tarball_url \ + | cut -d'"' -f 4 \ + | wget -qi - -O - \ + | tar -xzf - -C "${ZSH_PLUGIN_DIR}/${pluginName}" --strip-components=1 +} + +sourcePlug() { + pluginName="${1}" + userRepo="${2}" + [[ ! -n "$pluginName" || ! -n "$userRepo" ]] && throw "Missing 1 or more arguments." + ext=`[[ $3 == "theme" ]] && echo "zsh-theme" || echo "plugin.zsh"` + isPrivileged=`[[ $(print -P "%#") == '#' ]] && echo true || echo false` + + + [[ -f "${ZSH_PLUGIN_DIR}/${pluginName}/${pluginName}.${ext}" ]] \ + && source "${ZSH_PLUGIN_DIR}/${pluginName}/${pluginName}.${ext}" \ + || { + source `download "${pluginName}" "https://api.github.com/repos/${userRepo}/tags" \ + && echo "${ZSH_PLUGIN_DIR}/${pluginName}/${pluginName}.${ext}"` + } +} + +alias userctl="systemctl --user" + +# create plugin.d if not exist +test ! -d /etc/zsh_plugin.d && mkdir -vp /etc/zsh_plugin.d + +sourcePlug powerlevel10k romkatv/powerlevel10k theme + +# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. +# Initialization code that may require console input (password prompts, [y/n] +# confirmations, etc.) must go above this block; everything else may go below. +if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then + source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" +fi + +# sourcePlug zshrc freak2geek/zshrc +sourcePlug zsh-autosuggestions zsh-users/zsh-autosuggestions + +ZSH_AUTOSUGGEST_STRATEGY=(history completion) + +sourcePlug zsh-completions zsh-users/zsh-completions +sourcePlug fast-syntax-highlighting zdharma-continuum/fast-syntax-highlighting +sourcePlug zsh-history-substring-search zsh-users/zsh-history-substring-search + +# Keybindings + +bindkey '^[[A' history-substring-search-up +bindkey '^[[B' history-substring-search-down + +typeset -g -A key + +key[Home]="${terminfo[khome]}" +key[End]="${terminfo[kend]}" +key[Insert]="${terminfo[kich1]}" +key[Backspace]="${terminfo[kbs]}" +key[Delete]="${terminfo[kdch1]}" +key[Up]="${terminfo[kcuu1]}" +key[Down]="${terminfo[kcud1]}" +key[Left]="${terminfo[kcub1]}" +key[Right]="${terminfo[kcuf1]}" +key[PageUp]="${terminfo[kpp]}" +key[PageDown]="${terminfo[knp]}" +key[Shift-Tab]="${terminfo[kcbt]}" + +[[ -n "${key[Home]}" ]] && bindkey -- "${key[Home]}" beginning-of-line +[[ -n "${key[End]}" ]] && bindkey -- "${key[End]}" end-of-line +[[ -n "${key[Insert]}" ]] && bindkey -- "${key[Insert]}" overwrite-mode +[[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}" backward-delete-char +[[ -n "${key[Delete]}" ]] && bindkey -- "${key[Delete]}" delete-char +[[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-history +[[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-history +[[ -n "${key[Left]}" ]] && bindkey -- "${key[Left]}" backward-char +[[ -n "${key[Right]}" ]] && bindkey -- "${key[Right]}" forward-char +[[ -n "${key[PageUp]}" ]] && bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history +[[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history +[[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}" reverse-menu-complete + +if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then + autoload -Uz add-zle-hook-widget + function zle_application_mode_start { echoti smkx } + function zle_application_mode_stop { echoti rmkx } + add-zle-hook-widget -Uz zle-line-init zle_application_mode_start + add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop +fi + +key[Control-Left]="${terminfo[kLFT5]}" +key[Control-Right]="${terminfo[kRIT5]}" + +[[ -n "${key[Control-Left]}" ]] && bindkey -- "${key[Control-Left]}" backward-word +[[ -n "${key[Control-Right]}" ]] && bindkey -- "${key[Control-Right]}" forward-word diff --git a/utils/pkg.sh b/utils/pkg.sh new file mode 100644 index 0000000..67d82f3 --- /dev/null +++ b/utils/pkg.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +[ -f "/etc/os-release" ] && . /etc/os-release + +function pkg() { + command=$1 + shift + package=$1 + shift + + case "${command}" in + install) + if [[ "${ID}" == "opensuse-microos" ]]; then + if [ ! "$(command -v "${package}")" ]; then + sudo transactional-update --continue --drop-if-no-change run bash -c "zypper dup; zypper install ${package}" + else + echo "${package} is Already installed; Skipping." + fi + fi + ;; + *) + echo "Command does not exist" + exit 1 + ;; + esac + +}