use sd for managin scripts

This commit is contained in:
Al-Hassan Abdel-Raouf 2022-12-31 23:33:21 +02:00
parent fcda7ed476
commit df5c4def7e
8 changed files with 50 additions and 18 deletions

View File

@ -33,3 +33,6 @@ zsh-users/zsh-autosuggestions
zsh-users/zsh-completions
zdharma-continuum/fast-syntax-highlighting kind:defer
zsh-users/zsh-history-substring-search
# Managing Personal Scripts
ianthehenry/sd

View File

@ -42,3 +42,5 @@ fpath+=( /home/alhassan/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLA
zsh-defer source /home/alhassan/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-zdharma-continuum-SLASH-fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
fpath+=( /home/alhassan/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-history-substring-search )
source /home/alhassan/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-history-substring-search/zsh-history-substring-search.plugin.zsh
fpath+=( /home/alhassan/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-ianthehenry-SLASH-sd )
source /home/alhassan/.cache/antidote/https-COLON--SLASH--SLASH-github.com-SLASH-ianthehenry-SLASH-sd/sd.plugin.zsh

View File

@ -1,9 +0,0 @@
value=$(<./adblock-list)
echo $value
for entry in $value
do
./adblock-update.sh $entry
done

View File

@ -0,0 +1,15 @@
#!/bin/bash
parent_path=$(
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd -P
)
cd "$parent_path"
value=$(<./adblock-list)
echo $value
for entry in $value; do
./adblock-update.sh $entry
done

View File

@ -7,10 +7,16 @@
# URL URL of the filterlist to download
# -h, --help Display this help-message and exit
parent_path=$(
cd "$(dirname "${BASH_SOURCE[0]}")"
pwd -P
)
cd "$parent_path"
# help message
function usage ()
{
cat << EOF
function usage() {
cat <<EOF
Usage: $0 [-h] [URL]
This script can be used to download/update filterlists for the luakit adblock-module.
It will only update the file if the server-side version is newer.
@ -21,14 +27,13 @@ EOF
}
# check for $XDG_DATA_HOME or fallback
[[ -z "$XDG_DATA_HOME" ]] && DATADIR="$HOME/.local/share" || DATADIR="$XDG_DATA_HOME"
[[ -z $XDG_DATA_HOME ]] && DATADIR="$HOME/.local/share" || DATADIR="$XDG_DATA_HOME"
# use URL if given
if (( $# == 1 )) || (( $# == 0 )); then
[[ -z $1 ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]] && usage && exit 0 # check for -h flag
if (($# == 1)) || (($# == 0)); then
[[ -z $1 ]] || [[ $1 == "-h" ]] || [[ $1 == "--help" ]] && usage && exit 0 # check for -h flag
listname="${1}"
elif (( $# > 1 ));then
elif (($# > 1)); then
usage
exit 11
fi
@ -43,7 +48,7 @@ fi
wget -N --connect-timeout=10 --tries=20 --retry-connrefused --waitretry=5 ${listname}
# if download failed move old file back in place
if (( $? != 0 )); then
if (($? != 0)); then
[[ -f ${listname}.b ]] && cp -p ${listname}.b ${listname} && rm ${listname}.b
echo "Error: List Download Failed!"
exit 11

16
sd/usephp Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
[ "$#" -lt "1" ] && {
echo "Configure current shell to use a specific major PHP version.
Usage: usephp 7"
exit 0
}
binary="php${1}"
wanted="/usr/bin/${binary}"
[ ! -f "${wanted}" ] && {
echo "'${binary}' not found. Using 'php'."
wanted="/usr/bin/php"
}
ln -sf "${wanted}" "${HOME}/bin/php"
inUse=$(php -nr "echo phpversion();")
echo "Shell configured to use PHP ${inUse}."