Add autoinstall for packages (vim-plug, starship, ...)

This commit is contained in:
Tobias Reisinger 2022-09-13 21:28:05 +02:00
parent e448e719e8
commit 866bbcae20
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
5 changed files with 57 additions and 101 deletions

23
.bin/autoinstall-packages Executable file
View file

@ -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

View file

@ -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 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 rmtrash)" ] && alias rm='rmtrash'
[ -x "$(command -v rmdirtrash)" ] && alias rmdir='rmdirtrash' [ -x "$(command -v rmdirtrash)" ] && alias rmdir='rmdirtrash'

View file

@ -7,6 +7,8 @@ then
rm "$HOME/.zshrc" rm "$HOME/.zshrc"
fi fi
autoinstall-packages
# Set name of the theme to load --- if set to "random", it will # 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, # 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 # to know which specific one was loaded, run: echo $RANDOM_THEME
@ -67,6 +69,18 @@ HIST_STAMPS="yyyy-mm-dd"
# Would you like to use another custom folder than $ZSH/custom? # Would you like to use another custom folder than $ZSH/custom?
ZSH_CUSTOM=$ZDOTDIR/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? # Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/ # Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/ # Custom plugins may be added to $ZSH_CUSTOM/plugins/
@ -88,6 +102,7 @@ plugins=(
'safe-paste' 'safe-paste'
'sudo' 'sudo'
'vi-mode' 'vi-mode'
'zsh-syntax-highlighting'
) )
source $ZSH/oh-my-zsh.sh source $ZSH/oh-my-zsh.sh
@ -106,7 +121,4 @@ export SAVEHIST=1000000
export HISTSIZE=1000000 export HISTSIZE=1000000
export HISTFILE="$HOME/.cache/zsh_history" 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)" [ -x "$(command -v starship)" ] && eval "$(starship init zsh)"

View file

@ -1,47 +0,0 @@
# doas-zsh-plugin
Easily prefix your current or previous commands with `doas` by pressing <kbd>esc</kbd> 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 <kbd>esc</kbd> 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 <kbd>esc</kbd> 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)

View file

@ -1,32 +0,0 @@
# ------------------------------------------------------------------------------
# Description
# -----------
#
# doas will be inserted before the command
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Anatoly <akopyl@radner.ru>
#
# ------------------------------------------------------------------------------
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