chore(script): apply shellcheck fixes

This commit is contained in:
Rob Watson 2023-10-07 10:43:32 +02:00
parent ff7d772d46
commit 6b78c20555
34 changed files with 102 additions and 238 deletions

View File

@ -4,8 +4,8 @@
set -e
if [ $(uname -s) = "Darwin" ]; then
if [ "$(uname -s)" = "Darwin" ]; then
echo "" # TODO
else # Linux
echo "$(cat /sys/class/power_supply/BAT0/capacity)"
cat /sys/class/power_supply/BAT0/capacity
fi

View File

@ -8,8 +8,7 @@ set -e
branchname=$(git bn)
if [ "$branchname" = "HEAD" ]; then
branchoutput=$(git branch --list | grep rebasing)
if [ ! $? -eq 0 ]; then
if ! branchoutput=$(git branch --list | grep rebasing); then
exit 1
fi
@ -21,4 +20,4 @@ if [ "$branchname" = "HEAD" ]; then
fi
fi
printf $branchname
printf "%s" "$branchname"

View File

@ -9,11 +9,11 @@ set -e
pluginhome=$HOME/.vim/pack/git-plugins
cd $pluginhome/opt
find . -mindepth 1 -maxdepth 1 -type d -print0 | while read -d $'\0' pluginpath
cd "$pluginhome/opt"
find . -mindepth 1 -maxdepth 1 -type d -print0 | while read -rd $'\0' pluginpath
do
if ! grep -q "$pluginpath" $HOME/.config/nvim/init.vim ; then
basename=$(basename $pluginpath)
if ! grep -q "$pluginpath" "$HOME/.config/nvim/init.vim" ; then
basename=$(basename "$pluginpath")
echo "rm -rf $pluginhome/opt/$basename"
fi
done

View File

@ -1,59 +0,0 @@
#!/usr/bin/env ruby
#
# frozen_string_literal: true
# Create a Git repo on git.netflux.io
require 'json'
require 'net/http'
require 'optparse'
require 'uri'
options = {}
banner = 'Usage: createrepo [options] <reponame>'
OptionParser.new do |opts|
opts.banner = banner
opts.on('--private', 'Make repo private') do |v|
options[:private] = v
end
opts.on('-d', '--description=DESC', 'Description') do |v|
options[:description] = v
end
end.parse!
options[:name] = ARGV.pop.to_s.strip
if options[:name].empty?
puts banner
exit 1
end
auth_token = ENV['GIT_NETFLUX_IO_TOKEN']
if !auth_token || auth_token.empty?
puts 'Env var GIT_NETFLUX_IO_TOKEN must be set'
exit 1
end
uri = URI('https://git.netflux.io/api/v1/user/repos')
auth_string = "token #{auth_token}"
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'Authorization' => auth_string)
req.body = options.to_json
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
resp = http.request(req)
if resp.code != '201'
begin
errmsg = JSON.parse(resp.body)
puts errmsg['message']
rescue JSON::ParserError
puts resp.body
end
exit 1
end
repo = JSON.parse(resp.body)
puts "git remote add origin #{repo['ssh_url']}"
end

View File

@ -26,7 +26,7 @@ if [ ! -d "$path" ]; then
exit 1
fi
rm -rf $path
rm -rf "$path"
echo "Deleted $basename"

View File

@ -18,7 +18,7 @@ if [ -z "$filepattern" ]; then
filepattern="*"
fi
if [ $(uname -s) = "Linux" ]; then
if [ "$(uname -s)" = "Linux" ]; then
echo "TODO: fix for Linux"
fi

View File

@ -5,5 +5,5 @@
set -e
ssh-keygen -o -a 100 -t ed25519 -f $HOME/.ssh/id_ed25519 -C "$USER@$(hostname -s)"
cat $HOME/.ssh/id_ed25519.pub
ssh-keygen -o -a 100 -t ed25519 -f "$HOME/.ssh/id_ed25519" -C "$USER@$(hostname -s)"
cat "$HOME/.ssh/id_ed25519.pub"

View File

@ -13,9 +13,9 @@ if ! echo "$ghoutput" | grep -q 'https://'; then
exit 1
fi
url=$(echo $ghoutput | grep -o 'https://.*?' | tr -d '?')
url=$(echo "$ghoutput" | grep -o 'https://.*?' | tr -d '?')
if [ $(uname -s) = "Linux" ]; then
if [ "$(uname -s)" = "Linux" ]; then
progname="xdg-open"
else
progname="open" # macOS

View File

@ -9,6 +9,7 @@ unset BROWSER
if [ "$1" = '-a' ]; then
cmd='gh pr list --limit 100'
elif [ -z "$GITHUB_USERNAME" ]; then
# shellcheck disable=SC2016
echo 'set $GITHUB_USERNAME first'
exit 1
else
@ -16,7 +17,7 @@ else
fi
prid=$(eval "$cmd" | fzf | awk '{print $1}')
if [ -z $prid ]; then
if [ -z "$prid" ]; then
exit 0
fi
gh pr checkout $prid
gh pr checkout "$prid"

View File

@ -22,6 +22,6 @@ if echo "$output" | grep -q "no pull requests found"; then
echo "Opening new PR..."
gh pr create -w
else
echo $output
echo "$output"
exit $exitcode
fi

View File

@ -9,4 +9,4 @@ if [ "$1" = "-s" ]; then
fi
# TODO: fix for non-Darwin
git rev-parse $args HEAD | tr -d '\n' | pbcopy
git rev-parse "$args" HEAD | tr -d '\n' | pbcopy

View File

@ -14,27 +14,27 @@ if ! [ -x "$(command -v cargo)" ]; then
exit 1
fi
mkdir -p $HOME/dev $HOME/bin
mkdir -p "$HOME/dev" "$HOME/bin"
destdir=$HOME/dev/alacritty
if [ -d $destdir ]; then
if [ -d "$destdir" ]; then
echo "Updating alacritty..."
cd $destdir
cd "$destdir"
git pull --rebase
else
echo "Cloning alacritty..."
cd $HOME/dev
cd "$HOME/dev"
git clone -q https://github.com/alacritty/alacritty.git alacritty
fi
cd $destdir
cd "$destdir"
echo "Building alacritty..."
if [ $(uname -s) = "Darwin" ]; then
if [ "$(uname -s)" = "Darwin" ]; then
make app
sudo cp -av $destdir/target/release/osx/Alacritty.app /Applications/
sudo cp -av "$destdir/target/release/osx/Alacritty.app" /Applications/
else
cargo build --release
echo "Installing alacritty..."
cp $destdir/target/release/alacritty $HOME/bin/alacritty
cp "$destdir/target/release/alacritty" "$HOME/bin/alacritty"
fi
if [ -z "$ZDOTDIR" ]; then
@ -44,13 +44,13 @@ fi
echo "Installing ZSH completions..."
funcdir=$ZDOTDIR/functions
mkdir -p $funcdir
cp $destdir/extra/completions/_alacritty $funcdir/_alacritty
mkdir -p "$funcdir"
cp "$destdir/extra/completions/_alacritty" "$funcdir/_alacritty"
if [ $(uname -s) = "Linux" ]; then
if [ "$(uname -s)" = "Linux" ]; then
# TODO: fix for Manjaro/xfce4:
sudo cp $destdir/extra/logo/alacritty-term.svg /usr/share/pixmaps/Alacritty.svg
sudo desktop-file-install $destdir/extra/linux/Alacritty.desktop
sudo cp "$destdir/extra/logo/alacritty-term.svg" /usr/share/pixmaps/Alacritty.svg
sudo desktop-file-install "$destdir/extra/linux/Alacritty.desktop"
sudo update-desktop-database
fi

View File

@ -6,47 +6,49 @@
set -e
# General
mkdir -p $HOME/dev
ln -sfn $HOME/dev/dotfiles/script $HOME/script
mkdir -p "$HOME/dev"
ln -sfn "$HOME/dev/dotfiles/script" "$HOME/script"
# ZSH
mkdir -p $HOME/.config/zsh/functions
mkdir -p "$HOME/.config/zsh/functions"
# TODO: ZSH on Mac appears to load zshenv from ZDOTDIR, not HOME.
# Try to consolidate this.
if [ $(uname -s) = "Darwin" ]; then
if [ "$(uname -s)" = "Darwin" ]; then
envpath="$HOME/.config/zsh/.zshenv"
else
envpath="$HOME/.zshenv"
fi
ln -sfn $HOME/dev/dotfiles/zshenv "$envpath"
ln -sfn $HOME/dev/dotfiles/zshrc $HOME/.config/zsh/.zshrc
ln -sfn "$HOME/dev/dotfiles/zshenv" "$envpath"
ln -sfn "$HOME/dev/dotfiles/zshrc" "$HOME/.config/zsh/.zshrc"
secretsfile="$HOME/.config/zsh/.zshsecrets"
if [ ! -f "$secretsfile" ]; then
cp $HOME/dev/dotfiles/zshsecrets.example "$secretsfile"
cp "$HOME/dev/dotfiles/zshsecrets.example" "$secretsfile"
fi
# Tmux
ln -sfn $HOME/dev/dotfiles/tmux.conf $HOME/.tmux.conf
ln -sfn "$HOME/dev/dotfiles/tmux.conf" "$HOME/.tmux.conf"
# Vim
mkdir -p $HOME/.vim/pack/git-plugins/{opt,start}
ln -sfn $HOME/dev/dotfiles/vimrc $HOME/.vimrc
ln -sfn $HOME/dev/dotfiles/vim/after $HOME/.vim/after
mkdir -p "$HOME/.vim/pack/git-plugins/{opt,start}"
ln -sfn "$HOME/dev/dotfiles/vimrc" "$HOME/.vimrc"
ln -sfn "$HOME/dev/dotfiles/vim/after" "$HOME/.vim/after"
ln -sfn "$HOME/dev/dotfiles/vim/after" "$HOME/.vim/queries"
ln -sfn "$HOME/dev/dotfiles/vim/after" "$HOME/.vim/lua"
# Git
ln -sfn $HOME/dev/dotfiles/gitconfig $HOME/.gitconfig
mkdir -p $HOME/.config/git
ln -sfn $HOME/dev/dotfiles/gitignore $HOME/.config/git/ignore
ln -sfn "$HOME/dev/dotfiles/gitconfig" "$HOME/.gitconfig"
mkdir -p "$HOME/.config/git"
ln -sfn "$HOME/dev/dotfiles/gitignore" "$HOME/.config/git/ignore"
# Alacritty
if [ $(uname -s) = "Darwin" ]; then
if [ "$(uname -s)" = "Darwin" ]; then
alacrittyconfig="$HOME/dev/dotfiles/alacritty.macos.yml"
else
alacrittyconfig="$HOME/dev/dotfiles/alacritty.yml"
fi
ln -sfn "$alacrittyconfig" $HOME/.config/alacritty.yml
ln -sfn "$alacrittyconfig" "$HOME/.config/alacritty.yml"
echo "Done"

View File

@ -3,18 +3,18 @@
# Clone or update nvim to $HOME/dev/neovim, build and install to $HOME/local
set -e
mkdir -p $HOME/dev
mkdir -p "$HOME/dev"
destdir=$HOME/dev/neovim
if [ -d $destdir ]; then
if [ -d "$destdir" ]; then
echo "Updating nvim..."
cd $destdir
cd "$destdir"
git pull --rebase
else
echo "Cloning nvim..."
cd $HOME/dev
cd "$HOME/dev"
git clone -q https://github.com/neovim/neovim.git neovim
cd $destdir
cd "$destdir"
fi
make CMAKE_BUILD_TYPE=Release CMAKE_INSTALL_PREFIX=$HOME/local
make CMAKE_BUILD_TYPE=Release CMAKE_INSTALL_PREFIX="$HOME/local"
make install

View File

@ -2,7 +2,7 @@
#
# install packages for a new arch or manjaro installation. requires sudo
if [[ $euid > 0 ]]; then
if [[ $EUID -gt 0 ]]; then
echo "requires administrative privileges"
exit 1
fi
@ -21,4 +21,4 @@ pacman -S --needed --noconfirm base-devel \
syncthing \
ttf-ubuntu-font-family # ubuntu mono font for alacritty
sudo -u $SUDO_USER ./script/installpackagesnonroot
sudo -u "$SUDO_USER" ./script/installpackagesnonroot

View File

@ -4,7 +4,8 @@
# https://rustup.rs/
curl --proto '=https' --tlsv1.2 -ssf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
# shellcheck disable=SC1091
source "$HOME/.cargo/env"
# https://github.com/dandavison/delta#installation
cargo install git-delta

View File

@ -1,28 +0,0 @@
#!/usr/bin/env bash
#
# Clone or update vim to $HOME/dev/vim, build and install to $HOME/local
set -e
mkdir -p $HOME/dev
destdir=$HOME/dev/vim
if [ -d $destdir ]; then
echo "Updating vim..."
cd $destdir
git pull --rebase
else
echo "Cloning vim..."
cd $HOME/dev
git clone -q https://github.com/vim/vim.git vim
fi
cd $destdir
# TODO: https://stackoverflow.com/questions/53135863/macos-mojave-ruby-config-h-file-not-found
opts="--enable-luainterp --enable-python3interp --with-features=huge --enable-multibyte --enable-gui=gtk2"
if [ ! $(uname -s) = "Darwin" ]; then
opts="$opts --with-rubyinterp --with-x"
fi
./configure --prefix=$HOME/local $opts
make -j6
make install

View File

@ -7,18 +7,18 @@ set -e
# Note: not currently updated automatically by `updatevimplugins`
url="https://raw.githubusercontent.com/junegunn/fzf/master/plugin/fzf.vim"
echo "Fetching $url..."
mkdir -p $HOME/.vim/plugin
curl -sL -o $HOME/.vim/plugin/fzf.vim https://raw.githubusercontent.com/junegunn/fzf/master/plugin/fzf.vim
mkdir -p "$HOME/.vim/plugin"
curl -sL -o "$HOME/.vim/plugin/fzf.vim" https://raw.githubusercontent.com/junegunn/fzf/master/plugin/fzf.vim
# Relies on vimrc containing lines e.g.:
# packadd! rust.vim " https://github.com/rust-lang/rust.vim.git
pluginhome=$HOME/.vim/pack/git-plugins/opt
mkdir -p $pluginhome
cd $pluginhome
mkdir -p "$pluginhome"
cd "$pluginhome"
grep packadd! $HOME/.config/nvim/init.vim | grep -o 'https.*$' | while read -r url ; do
dirname=$(basename $url .git)
grep packadd! "$HOME/.config/nvim/init.vim" | grep -o 'https.*$' | while read -r url ; do
dirname=$(basename "$url" .git)
if [ -d "$dirname" ]; then
echo "Exists: $dirname"
else

View File

@ -5,12 +5,12 @@
set -e
if [ -z "$JIRADOMAIN" ]; then
# shellcheck disable=SC2016
echo 'set $JIRADOMAIN first'
exit 1
fi
branchname="$(branchname)"
if [ ! $? -eq 0 ]; then
if ! branchname="$(branchname)"; then
echo "branchname returned exit code: $?"
exit 1
fi
@ -21,11 +21,10 @@ if ! echo "$branchname" | grep -q "/"; then
fi
ticket=$(echo "$branchname" | cut -d "/" -f1 | tr '[:lower:]' '[:upper:]')
url="$JIRADOMAIN/browse/$ticket"
if [ "$1" == "-b" ]; then
if [ $(uname -s) = "Linux" ]; then
if [ "$(uname -s)" = "Linux" ]; then
progname="xdg-open"
else
progname="open" # macOS
@ -35,4 +34,4 @@ if [ "$1" == "-b" ]; then
exit $?
fi
printf $url
printf "%s" "$url"

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
context=$(kubectl config get-contexts -o name | fzf)
if [ $? -ne 0 ]; then
if ! context=$(kubectl config get-contexts -o name | fzf); then
exit $?
fi

View File

@ -7,11 +7,11 @@ set -e
url='https://api.ipify.org?format=text'
if [ "$1" = "-c" ]; then
if [ $(uname -s) = "Darwin" ]; then
curl -s $url | pbcopy
if [ "$(uname -s)" = "Darwin" ]; then
curl -s "$url" | pbcopy
else
curl -s $url | xclip -i
curl -s "$url" | xclip -i
fi
else
curl -s $url
curl -s "$url"
fi

View File

@ -4,7 +4,7 @@
set -e
if [ $(uname -s) = "Darwin" ]; then
if [ "$(uname -s)" = "Darwin" ]; then
uptime | grep -o "[0-9]\+\.[0-9]\+ [0-9]\+\.[0-9]\+ [0-9]\+\.[0-9]\+"
else # Linux
cut -d " " -f 1-3 /proc/loadavg

View File

@ -9,17 +9,17 @@ set -e
if [ -z "$1" ]; then
cwd=$(pwd)
sessionname=$(basename $cwd)
sessionname=$(basename "$cwd")
else
sessionname="$1"
fi
tmux_new_result=$(tmux new -d -s $sessionname 2>&1) || true
tmux_new_result=$(tmux new -d -s "$sessionname" 2>&1) || true
exitcode=$?
if echo "$tmux_new_result" | grep -q "duplicate session"; then
echo "Session $sessionname already exists. Attaching..."
tmux new -d -A -s $sessionname
tmux new -d -A -s "$sessionname"
exit 0
fi
@ -29,9 +29,9 @@ if [ $exitcode -ne 0 ]; then
fi
# TODO: fix sessionname containing full stop which are renamed by tmux
tmux rename-window -t $sessionname:1 cli
tmux new-window -t $sessionname -n vim zsh -ic nvim
tmux select-window -t $sessionname:1
tmux rename-window -t "$sessionname:1" cli
tmux new-window -t "$sessionname" -n vim zsh -ic nvim
tmux select-window -t "$sessionname:1"
# https://github.com/tmux/tmux/issues/2064
sleep 0.5
tmux attach -t $sessionname
tmux attach -t "$sessionname"

View File

@ -1,19 +0,0 @@
#!/usr/bin/env bash
#
# Unstage a branch
set -e
branch=$(git rev-parse --abbrev-ref HEAD)
if [ -z "$1" ]; then
basebranch="master"
else
basebranch="$1"
fi
diff=$(git diff $basebranch...HEAD)
git co -q "$basebranch"
echo "$diff" | git apply
echo "Unstaged $branch against $basebranch successfully"
git diff --shortstat "HEAD...$branch"

View File

@ -2,7 +2,9 @@
#
# Update all AUR packages in $HOME/pkg
find $HOME/pkg -mindepth 1 -maxdepth 1 -type d -print0 | while read -d $'\0' pkgdir
set -euo pipefail
find "$HOME/pkg" -mindepth 1 -maxdepth 1 -type d -print0 | while read -rd $'\0' pkgdir
do
cd "$pkgdir"
pullres=$(git pull --rebase)

View File

@ -12,8 +12,10 @@ updatenvim
updatevimplugins
echo "Installing gopls..."
cd $HOME
cd "$HOME"
go install golang.org/x/tools/gopls@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
# TODO: run installdotfiles?
echo "Done"

View File

@ -1,27 +0,0 @@
#!/usr/bin/env bash
#
# Build and push Invidious
#
# TODO: remove Docker hub, push with SSH.
set -e
destdir=$HOME/dev/invidious
image=netfluxio/invidious:latest
remotehost=netflux
if [ ! -d $destdir ]; then
echo "Cloning invidious..."
cd $HOME/dev
git clone -q --depth=1 https://github.com/iv-org/invidious.git invidious
else
echo "Updating invidious..."
cd $destdir
git pull --rebase
fi
cd $destdir
docker build -t $image -f docker/Dockerfile .
docker push $image
ssh $remotehost 'cd dev/netflux-internals && docker-compose pull invidious && docker-compose up -d --force-recreate --no-deps invidious'

View File

@ -1,12 +0,0 @@
#!/usr/bin/env bash
#
# updatenetflux - pull and restart containers on remote server
set -e
remotehost=netflux
ssh $remotehost 'cd dev/netflux-internals && git pull --rebase && docker-compose down -v && docker-compose pull && docker-compose up -d --force-recreate'
# invidious requires a local build, managed by a separate script.
updateinvidious

View File

@ -1 +0,0 @@
installvim

View File

@ -5,13 +5,13 @@
set -e
pluginhome=$HOME/.vim/pack/git-plugins
cd $pluginhome
cd "$pluginhome"
find . -mindepth 2 -maxdepth 2 -type d -print0 | while read -d $'\0' pluginpath
find . -mindepth 2 -maxdepth 2 -type d -print0 | while read -rd $'\0' pluginpath
do
cd $pluginpath
basename=$(basename $pluginpath)
printf "In $basename.. "
cd "$pluginpath"
basename=$(basename "$pluginpath")
printf "In %s.. " "$basename"
git pull --rebase
cd $pluginhome
cd "$pluginhome"
done

View File

@ -2,4 +2,6 @@
#
# uuidprint - generate and print a lower-case UUID v4
set -e
uuidgen | tr '[:upper:]' '[:lower:]' | tr -d '\n'

View File

@ -2,5 +2,7 @@
#
# uuidyank - generate and copy a lower-case UUID v4
set -e
# TODO: fix for Linux
uuidprint | pbcopy

View File

@ -4,7 +4,7 @@
set -e
if [[ $EUID > 0 ]]; then
if [[ $EUID -gt 0 ]]; then
echo "requires administrative privileges"
exit 1
fi

View File

@ -4,7 +4,7 @@
set -e
if [[ $EUID > 0 ]]; then
if [[ $EUID -gt 0 ]]; then
echo "requires administrative privileges"
exit 1
fi