fix: add some compatibility options

this commit introduces the `has` function.
Now I can ensure that any command I want to alias or call is available
first.

This should allow the config to automatically slot in even where systems
aren't configured in the way I would expect
This commit is contained in:
Robert Morrison 2022-12-05 21:29:10 +00:00
parent a029d2f348
commit 5d1484881e
Signed by: robert
GPG Key ID: 73E012EB3F4EC696
5 changed files with 46 additions and 24 deletions

33
aliases
View File

@ -34,21 +34,23 @@
## Use Exa instead of ls ## Use Exa instead of ls
## REQUIRES NERD FONT ## REQUIRES NERD FONT
alias ls='exa --icons --group-directories-first' has exa && alias ls='exa --icons --group-directories-first'
## Shorten xdg-open ## Shorten xdg-open
alias xopen='xdg-open' has xdg-open && alias xopen='xdg-open'
## cls Clear Screen run ls ## cls Clear Screen run ls
alias cls='clear; ls' alias cls='clear; ls'
## Shorten scriptedit ## Shorten scriptedit
## REQUIRES scriptedit (Script) ## REQUIRES scriptedit (Script)
alias se='scriptedit' has scriptedit && alias se='scriptedit'
## YouTube downloader ## YouTube downloader
if has youtube-dl ; then
alias yt='youtube-dl' alias yt='youtube-dl'
alias yta='youtube-dl --ignore-config --add-metadata --ignore-errors --extract-audio --format "bestaudio/best"' alias yta='youtube-dl --ignore-config --add-metadata --ignore-errors --extract-audio --format "bestaudio/best"'
fi
## ##
alias cp='cp --interactive --verbose' alias cp='cp --interactive --verbose'
@ -62,10 +64,10 @@ alias grep='grep --color=auto'
alias ip='ip --color=auto' alias ip='ip --color=auto'
## Open Vimwiki ## Open Vimwiki
alias vw='nvim -c VimwikiIndex' has nvim && alias vw='nvim -c VimwikiIndex'
## Change Wineprefix quick and EZ ## Change Wineprefix quick and EZ
alias ws='source wineselect' has wineselect && alias ws='source wineselect'
## zero a terminal session ## zero a terminal session
alias zero='dirs -c && clear' alias zero='dirs -c && clear'
@ -74,11 +76,24 @@ alias zero='dirs -c && clear'
# FileType Associations # # FileType Associations #
# extension=program # # extension=program #
######################### #########################
if has nvim; then
VIM=nvim
elif has vim; then
VIM=vim
elif has vi; then
VIM=vi
else
VIM=''
fi
alias -s tex=nvim if [[ -n $VIM ]]; then
alias -s html=nvim alias -s tex=$VIM
alias -s pdf=zathura alias -s html=$VIM
alias -s md=nvim alias -s md=$VIM
fi
unset $VIM
has zathura && alias -s pdf=zathura
# vim: set ft=zsh ts=2 sw=2 tw=0 noet : # vim: set ft=zsh ts=2 sw=2 tw=0 noet :

4
chpwd
View File

@ -1,6 +1,4 @@
HAS_GLOW="$(command -v glow)"
chpwd() { chpwd() {
[ -z $HAS_GLOW ] && return 0 [ ! has glow ] && return 0
find $PWD -maxdepth 1 -iname 'readme.md' -exec glow {} \; find $PWD -maxdepth 1 -iname 'readme.md' -exec glow {} \;
} }

8
functions/has Normal file
View File

@ -0,0 +1,8 @@
## Has function
has() {
Command=$1
[[ -z $Command ]] && return 1
command -v $Command > /dev/null 2>&1
}

8
greet
View File

@ -1,6 +1,4 @@
#!/bin/sh has colours.sh && colours.sh
colours.sh
echo '╭───────────╮' echo '╭───────────╮'
echo '│ Welcome!! │' echo '│ Welcome!! │'
echo '╰───────────╯' echo '╰───────────╯'
@ -15,5 +13,5 @@ if [ -d "$HOME/tmp" ]; then
fi fi
fi fi
fi fi
randomVerse has randomVerse && randomVerse
colours.sh has colours.sh && colours.sh

5
zshrc
View File

@ -22,6 +22,7 @@ fpath=( $ZDOTDIR/functions $fpath )
autoload CleanTmp autoload CleanTmp
autoload setTermTitle autoload setTermTitle
autoload tempPersist autoload tempPersist
autoload has
## Source Other files ## Source Other files
source ${ZDOTDIR}/aliases source ${ZDOTDIR}/aliases
@ -46,10 +47,12 @@ zle -N edit-command-line
bindkey "^X^E" edit-command-line bindkey "^X^E" edit-command-line
## Enable gpg-agent support ## Enable gpg-agent support
if [[ "$USE_GPG_AGENT" == "true" ]]; then
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket) export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
gpgconf --launch gpg-agent gpgconf --launch gpg-agent
gpg-connect-agent /bye gpg-connect-agent /bye
export GPG_TTY=$(tty) export GPG_TTY=$(tty)
fi
## Load external stuff ## Load external stuff
@ -83,4 +86,4 @@ source $ZDOTDIR/ZshPlug/ZshPlug.zsh
[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" history-beginning-search-backward [[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" history-beginning-search-backward
[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" history-beginning-search-forward [[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" history-beginning-search-forward
$ZDOTDIR/greet source $ZDOTDIR/greet