From 866bbcae201ddbd400e6b5674768503042e1c761 Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Tue, 13 Sep 2022 21:28:05 +0200 Subject: [PATCH] Add autoinstall for packages (vim-plug, starship, ...) --- .bin/autoinstall-packages | 23 ++++++++ .config/aliasrc | 2 +- .config/zsh/.zshrc | 54 +++++++++++-------- .config/zsh/custom/plugins/doas/README.md | 47 ---------------- .../zsh/custom/plugins/doas/doas.plugin.zsh | 32 ----------- 5 files changed, 57 insertions(+), 101 deletions(-) create mode 100755 .bin/autoinstall-packages delete mode 100644 .config/zsh/custom/plugins/doas/README.md delete mode 100644 .config/zsh/custom/plugins/doas/doas.plugin.zsh diff --git a/.bin/autoinstall-packages b/.bin/autoinstall-packages new file mode 100755 index 0000000..bc89f7d --- /dev/null +++ b/.bin/autoinstall-packages @@ -0,0 +1,23 @@ +#!/usr/bin/env sh + +vim_autoload_dir="$HOME/.config/vim/autoload" +if [ ! -f "$vim_autoload_dir/plug.vim" ] +then + mkdir -p "$vim_autoload_dir" + cd "$vim_autoload_dir" || exit + curl -o "plug.vim" "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" + [ -x "$(command -v vim)" ] && yes | vim +'PlugInstall --sync' +qa --not-a-term +fi + +nvim_dir="$HOME/.config/nvim" +if [ ! -d "$nvim_dir" ] +then + git clone https://github.com/AstroNvim/AstroNvim "$nvim_dir" + [ -x "$(command -v nvim)" ] && nvim --headless -c 'autocmd User PackerComplete quitall' -c 'PackerSync' +fi + +if [ ! -x "$(command -v starship)" ] +then + mkdir -p "$HOME/.local/bin" + curl -sS "https://starship.rs/install.sh" | BIN_DIR="$HOME/.local/bin" FORCE=1 sh +fi diff --git a/.config/aliasrc b/.config/aliasrc index aa40282..6c91d96 100644 --- a/.config/aliasrc +++ b/.config/aliasrc @@ -63,7 +63,7 @@ alias xdebug='XDEBUG_CONFIG="remote_host=127.0.0.1 remote_port=9003"' [ -x "$(command -v bat)" ] && alias cat='bat -pp' -[ -x "$(command -v exa)" ] && alias ls='exa -lhF --git --icons --color=always --color-scale --time-style=long-iso' +[ -x "$(command -v exa)" ] && alias ls='exa -lhF --git --icons --color=always --color-scale --time-style=long-iso --group-directories-first' [ -x "$(command -v rmtrash)" ] && alias rm='rmtrash' [ -x "$(command -v rmdirtrash)" ] && alias rmdir='rmdirtrash' diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index b5e2282..4e74b5b 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -2,11 +2,13 @@ source "$HOME/.config/environment" if [ ! -f "$ZSH/oh-my-zsh.sh" ] then - echo "Installing oh-my-zsh" - RUNZSH="no" sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" > /dev/null - rm "$HOME/.zshrc" + echo "Installing oh-my-zsh" + RUNZSH="no" sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" > /dev/null + rm "$HOME/.zshrc" fi +autoinstall-packages + # Set name of the theme to load --- if set to "random", it will # load a random theme each time oh-my-zsh is loaded, in which case, # to know which specific one was loaded, run: echo $RANDOM_THEME @@ -67,27 +69,40 @@ HIST_STAMPS="yyyy-mm-dd" # Would you like to use another custom folder than $ZSH/custom? ZSH_CUSTOM=$ZDOTDIR/custom +function omz_install_custom_plugin() { + plugin_path="$ZSH_CUSTOM/plugins/$1" + if [ ! -d "$plugin_path" ] + then + echo "Installing plugin $1" + git clone "$2" "$plugin_path" >/dev/null 2>&1 + fi +} + +omz_install_custom_plugin "zsh-syntax-highlighting" "https://github.com/zsh-users/zsh-syntax-highlighting.git" + + # Which plugins would you like to load? # Standard plugins can be found in $ZSH/plugins/ # Custom plugins may be added to $ZSH_CUSTOM/plugins/ # Example format: plugins=(rails git textmate ruby lighthouse) # Add wisely, as too many plugins slow down shell startup. plugins=( - 'colored-man-pages' - 'copypath' - 'copyfile' - 'cp' - 'docker' - 'docker-compose' - 'extract' - 'git' - 'git-auto-status' - 'jump' - 'laravel5' - 'rust' - 'safe-paste' - 'sudo' - 'vi-mode' + 'colored-man-pages' + 'copypath' + 'copyfile' + 'cp' + 'docker' + 'docker-compose' + 'extract' + 'git' + 'git-auto-status' + 'jump' + 'laravel5' + 'rust' + 'safe-paste' + 'sudo' + 'vi-mode' + 'zsh-syntax-highlighting' ) source $ZSH/oh-my-zsh.sh @@ -106,7 +121,4 @@ export SAVEHIST=1000000 export HISTSIZE=1000000 export HISTFILE="$HOME/.cache/zsh_history" -# Load zsh-syntax-highlighting; should be last. -source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 2>/dev/null - [ -x "$(command -v starship)" ] && eval "$(starship init zsh)" diff --git a/.config/zsh/custom/plugins/doas/README.md b/.config/zsh/custom/plugins/doas/README.md deleted file mode 100644 index 7b62f84..0000000 --- a/.config/zsh/custom/plugins/doas/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# doas-zsh-plugin - -Easily prefix your current or previous commands with `doas` by pressing esc twice - -To use it, add the following to your zshrc: - -```console -plugins=(doas) -``` - -## Usage - -### Current typed commands - -Say you have typed a long command and forgot to add `doas` in front: - -```console -$ apt-get install build-essential -``` - -By pressing the esc key twice, you will have the same command with `doas` prefixed without typing: - -```console -$ doas apt-get install build-essential -``` - -### Previous executed commands - -Say you want to delete a system file and denied: - -```console -$ rm some-system-file.txt --su: some-system-file.txt: Permission denied -$ -``` - -By pressing the esc key twice, you will have the same command with `doas` prefixed without typing: - -```console -$ rm some-system-file.txt --su: some-system-file.txt: Permission denied -$ doas rm some-system-file.txt -Password: -$ -``` - -Plugin inspired by sudo plugin by [Dongweiming](https://github.com/dongweiming) diff --git a/.config/zsh/custom/plugins/doas/doas.plugin.zsh b/.config/zsh/custom/plugins/doas/doas.plugin.zsh deleted file mode 100644 index 27e0ca8..0000000 --- a/.config/zsh/custom/plugins/doas/doas.plugin.zsh +++ /dev/null @@ -1,32 +0,0 @@ -# ------------------------------------------------------------------------------ -# Description -# ----------- -# -# doas will be inserted before the command -# -# ------------------------------------------------------------------------------ -# Authors -# ------- -# -# * Anatoly -# -# ------------------------------------------------------------------------------ - -doas-command-line() { - [[ -z $BUFFER ]] && LBUFFER="$(fc -ln -1)" - if [[ $BUFFER == doas\ * ]]; then - if [[ ${#LBUFFER} -le 4 ]]; then - RBUFFER="${BUFFER#doas }" - LBUFFER="" - else - LBUFFER="${LBUFFER#doas }" - fi - else - LBUFFER="doas $LBUFFER" - fi -} -zle -N doas-command-line -# Defined shortcut keys: [Esc] [Esc] -bindkey -M emacs '\e\e' doas-command-line -bindkey -M vicmd '\e\e' doas-command-line -bindkey -M viins '\e\e' doas-command-line