Skip to content

Commit 6f7e9c9

Browse files
author
Ira Abramov
committed
added shfmt tests and let it rip the code...
1 parent dd630d1 commit 6f7e9c9

17 files changed

+444
-395
lines changed

.pre-commit-config.yaml

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
---
4+
# fail_fast: true
5+
minimum_pre_commit_version: 1.18.1
6+
exclude: "docs/_build/"
17
repos:
2-
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
39
rev: v2.3.0
410
hooks:
5-
- id: check-yaml
6-
- id: end-of-file-fixer
7-
- id: trailing-whitespace
11+
- id: trailing-whitespace
12+
exclude: ".(md|rst)$"
13+
- id: end-of-file-fixer
14+
- id: check-merge-conflict
15+
- id: mixed-line-ending
16+
- id: check-added-large-files
17+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
18+
rev: 2.1.5
19+
hooks:
20+
- id: git-check # Configure in .gitattributes
21+
- id: shellcheck
22+
exclude: ".bats$"
23+
- id: shfmt
24+
exclude: ".bats$"
25+
- repo: https://github.com/Lucas-C/pre-commit-hooks
26+
rev: v1.1.7
27+
hooks:
28+
# - id: forbid-crlf
29+
- id: remove-crlf
30+
exclude: ".bat$"

bootstrap.sh

+35-27
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,26 @@ set -e
66
sudo -v
77

88
# Keep-alive: update existing `sudo` time stamp until this script has finished
9-
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
9+
while true; do
10+
sudo -n true
11+
sleep 60
12+
kill -0 "$$" || exit
13+
done 2>/dev/null &
1014

1115
if [[ "$OSTYPE" == "darwin"* ]]; then
1216

13-
#####################################
14-
##################### MacOS env setup
15-
#####################################
17+
#####################################
18+
##################### MacOS env setup
19+
#####################################
1620

17-
if ! hash brew 2>/dev/null ; then
21+
if ! hash brew 2>/dev/null; then
1822
echo "Installing Brew"
1923
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2024
fi
21-
hash brew 2>/dev/null || { echo "install brew first" ; exit 1 ; }
25+
hash brew 2>/dev/null || {
26+
echo "install brew first"
27+
exit 1
28+
}
2229

2330
brew doctor
2431
brew tap homebrew/cask-versions
@@ -28,14 +35,14 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
2835
brew install screen the_silver_searcher git curl hub fd fzf wget cmake node
2936

3037
# This little joke kills some of our nicest code.
31-
test -r /etc/bashrc_Apple_Terminal && \
38+
test -r /etc/bashrc_Apple_Terminal &&
3239
sudo mv /etc/bashrc_Apple_Terminal /etc/bashrc_Apple_Terminal.disabled
3340

34-
elif [[ -f /etc/redhat-release ]] ; then
41+
elif [[ -f /etc/redhat-release ]]; then
3542

36-
#####################################
37-
##################### RH-ish env setup
38-
#####################################
43+
#####################################
44+
##################### RH-ish env setup
45+
#####################################
3946

4047
# Enable Fedora
4148
sudo dnf copr enable tkbcopr/fd -y
@@ -46,22 +53,22 @@ elif [[ -f /etc/redhat-release ]] ; then
4653
git clone -q --depth 1 https://github.com/junegunn/fzf.git ~/.fzf &&
4754
~/.fzf/install --all --no-zsh --no-fish --no-update-rc
4855

49-
elif [[ "$(lsb_release -is)" == "Ubuntu" ]] || [[ "$(lsb_release -is)" == "Debian" ]] ; then
56+
elif [[ "$(lsb_release -is)" == "Ubuntu" ]] || [[ "$(lsb_release -is)" == "Debian" ]]; then
5057

51-
#####################################
52-
#################### Ubuntu env setup
53-
#####################################
58+
#####################################
59+
#################### Ubuntu env setup
60+
#####################################
5461

5562
echo "installing some essential packages"
5663
sudo apt update
5764
sudo apt install -y screen silversearcher-ag curl git \
58-
software-properties-common python3-pip rubygems tmux build-essential \
59-
cmake python3-dev nodejs npm python-dev
65+
software-properties-common python3-pip rubygems tmux build-essential \
66+
cmake python3-dev nodejs npm python-dev
6067

6168
# Adding backports, neovim and other useful bits.
6269
sudo add-apt-repository -u "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -cs)-backports main restricted universe multiverse"
6370

64-
if ! hash nvim 2>/dev/null ; then
71+
if ! hash nvim 2>/dev/null; then
6572
echo "install neovim, trying from default sources"
6673
sudo apt install -y neovim || {
6774
sudo add-apt-repository -u ppa:neovim-ppa/stable -y && sudo apt update
@@ -78,11 +85,11 @@ elif [[ "$(lsb_release -is)" == "Ubuntu" ]] || [[ "$(lsb_release -is)" == "Debia
7885
fi
7986

8087
# Download fd
81-
if hash fd 2>/dev/null ; then
88+
if hash fd 2>/dev/null; then
8289
echo "fd exists."
8390
else
8491
fdversion=7.2.0
85-
wget -q https://github.com/sharkdp/fd/releases/download/v${fdversion}/fd_${fdversion}_amd64.deb && \
92+
wget -q https://github.com/sharkdp/fd/releases/download/v${fdversion}/fd_${fdversion}_amd64.deb &&
8693
sudo dpkg -i fd_${fdversion}_amd64.deb
8794

8895
rm -Rf fd_${fdversion}_amd64.deb
@@ -99,23 +106,24 @@ fi
99106

100107
[[ -d "$HOME/.homesick/repos/homeshick" ]] ||
101108
git clone https://github.com/andsens/homeshick.git "$HOME/.homesick/repos/homeshick"
109+
# shellcheck disable=SC1091
102110
source "$HOME/.homesick/repos/homeshick/homeshick.sh"
103111

104112
# Have ensured that homesick is available
105113
hash homeshick 2>/dev/null || (echo "homeshick install failed" && exit 1)
106114

107115
pip3 install --upgrade powerline-status --user
108116

109-
if [[ -d "$HOME/.homesick/repos/dotfiles" ]] ; then
117+
if [[ -d "$HOME/.homesick/repos/dotfiles" ]]; then
110118
echo "Oh good, the homeshick is already checked out..."
111119
else
112120
## Clone dotfiles
113121
echo "Cloning the dotfiles"
114122
homeshick clone seefood/dotfiles
115123

116-
while read -r dir ; do
124+
while read -r dir; do
117125
mkdir -p ~/"${dir}"
118-
done < ~/.homesick/repos/dotfiles/.homesick_subdir
126+
done <~/.homesick/repos/dotfiles/.homesick_subdir
119127
fi
120128

121129
homeshick symlink dotfiles
@@ -128,16 +136,16 @@ echo "Make sure you have your correct settings in ~/.gitconfig.local"
128136
echo ''
129137
echo "Now installing vundle..."
130138
echo ''
131-
[[ -d ~/.vim/bundle/Vundle.vim ]] || \
139+
[[ -d ~/.vim/bundle/Vundle.vim ]] ||
132140
git clone -q https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
133141

134142
# Install pathogen for vim/neovim
135143
mkdir -p ~/.vim/autoload ~/.vim/bundle
136-
[[ -r ~/.vim/autoload/pathogen.vim ]] || \
144+
[[ -r ~/.vim/autoload/pathogen.vim ]] ||
137145
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
138146

139147
# Vim color scheme install
140-
if ! [[ -d ~/.vim/colors/wombat/ ]] ; then
148+
if ! [[ -d ~/.vim/colors/wombat/ ]]; then
141149
echo ''
142150
echo "Now installing vim wombat color scheme..."
143151
echo ''
@@ -149,7 +157,7 @@ echo 'fire up vundle installation'
149157
vim +PluginInstall +qall && echo 'vim plugins installed!'
150158

151159
# Bash color scheme
152-
if ! [[ -r ~/.dircolors ]] ; then
160+
if ! [[ -r ~/.dircolors ]]; then
153161
echo ''
154162
echo "Now installing solarized dark WSL color scheme..."
155163
echo ''

home/.bash.aliases.d/dev.general.sh

+20-21
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,28 @@ alias json='python -mjson.tool'
44
export GOPATH=~/go
55

66
function ps() {
7-
if [ $# -eq 0 ]; then
8-
command ps aux --sort rss
9-
elif [ $# -eq 2 ] && [ "$1" == '-p' ]; then
10-
local p=$2
7+
if [ $# -eq 0 ]; then
8+
command ps aux --sort rss
9+
elif [ $# -eq 2 ] && [ "$1" == '-p' ]; then
10+
local p=$2
1111

12-
mapfile -t plist < <(command ps -aef | awk -v x="${p}" ' $8 ~ x { print $2 } ')
13-
size=${#plist}
12+
mapfile -t plist < <(command ps -aef | awk -v x="${p}" ' $8 ~ x { print $2 } ')
13+
size=${#plist}
1414

15-
if [ "$size" -ne 0 ]; then
16-
command ps -u -p "${plist[@]}"
17-
command ps -u -p "${plist[@]}" | grep -v PID | awk '{ sum+=$3} END {print "CPU %:", sum}'
18-
command ps -u -p "${plist[@]}" | grep -v PID | awk '{ sum+=$4} END {print "MEM %:", sum}'
19-
else
20-
echo "[$p] process not found"
21-
fi
22-
else
23-
command ps "$@"
24-
fi
25-
lscpu | grep "CPU MHz"
15+
if [ "$size" -ne 0 ]; then
16+
command ps -u -p "${plist[@]}"
17+
command ps -u -p "${plist[@]}" | grep -v PID | awk '{ sum+=$3} END {print "CPU %:", sum}'
18+
command ps -u -p "${plist[@]}" | grep -v PID | awk '{ sum+=$4} END {print "MEM %:", sum}'
19+
else
20+
echo "[$p] process not found"
21+
fi
22+
else
23+
command ps "$@"
24+
fi
25+
lscpu | grep "CPU MHz"
2626
}
2727

28-
function yaml2json()
29-
{
30-
ruby -ryaml -rjson -e \
31-
'puts JSON.pretty_generate(YAML.load(ARGF))' "$@"
28+
function yaml2json() {
29+
ruby -ryaml -rjson -e \
30+
'puts JSON.pretty_generate(YAML.load(ARGF))' "$@"
3231
}

home/.bash.aliases.d/dev.git.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
function parse_git_branch {
4-
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1):/'
4+
git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1):/'
55
}
66

77
# Set vcprompt executable path for scm advance info in prompt (demula theme)

home/.bash.aliases.d/ira.private.sh

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
#!/bin/bash
2-
if [[ $USER =~ ^ira ]] ; then
3-
4-
# alias android-connect="mtpfs -o allow_other /media/GalaxyS2"
5-
# alias android-disconnect="fusermount -u /media/GalaxyS2"
6-
7-
# alias tat='vi ~/bin/tatsuya && strfile ~/bin/tatsuya'
8-
9-
alias uma='ssh [email protected]'
10-
11-
alias socks5="ssh scso.com -qfN -D 9051"
12-
alias mgif='v2gif *.webm *.mp4 -d'
13-
14-
if [[ "$OSTYPE" == "darwin"* ]]; then
15-
alias upt='brew upgrade'
16-
alias uupt='brew upgrade'
17-
else
18-
alias upt='sudo apt -u dist-upgrade'
19-
alias uupt='sudo apt update && upt'
20-
alias uptc='uupt ; sudo apt-get --purge autoremove `deborphan` `deborphan --guess-dev` `deborphan --guess-debug`'
21-
22-
#alias tat='vi ~/bin/tatsuya && strfile ~/bin/tatsuya'
23-
alias kgs="busctl --user call org.gnome.Shell /org/gnome/Shell org.gnome.Shell Eval s 'Meta.restart(\"Restarting…\")'"
24-
25-
function df () {
26-
if [[ "$*" ]] ; then
27-
/bin/df "$@"
28-
else
29-
/bin/df -hT -x squashfs -x tmpfs
30-
fi
31-
}
32-
fi
33-
34-
alias scan='sudo nmap -sS -Pn -R -v -O -f'
35-
alias beep="echo -e '\a'; sleep 1; echo -e '\a'; sleep 1; echo -e '\a'"
36-
type -P colorls >/dev/null && alias ls='colorls --sort-dirs --gs'
37-
export DEBEMAIL="[email protected]"
38-
export DEBFULLNAME="Ira Abramov"
2+
if [[ $USER =~ ^ira ]]; then
3+
4+
# alias android-connect="mtpfs -o allow_other /media/GalaxyS2"
5+
# alias android-disconnect="fusermount -u /media/GalaxyS2"
6+
7+
# alias tat='vi ~/bin/tatsuya && strfile ~/bin/tatsuya'
8+
9+
alias uma='ssh [email protected]'
10+
11+
alias socks5="ssh scso.com -qfN -D 9051"
12+
alias mgif='v2gif *.webm *.mp4 -d'
13+
14+
if [[ "$OSTYPE" == "darwin"* ]]; then
15+
alias upt='brew upgrade'
16+
alias uupt='brew upgrade'
17+
else
18+
alias upt='sudo apt -u dist-upgrade'
19+
alias uupt='sudo apt update && upt'
20+
alias uptc='uupt ; sudo apt-get --purge autoremove `deborphan` `deborphan --guess-dev` `deborphan --guess-debug`'
21+
22+
#alias tat='vi ~/bin/tatsuya && strfile ~/bin/tatsuya'
23+
alias kgs="busctl --user call org.gnome.Shell /org/gnome/Shell org.gnome.Shell Eval s 'Meta.restart(\"Restarting…\")'"
24+
25+
function df() {
26+
if [[ "$*" ]]; then
27+
/bin/df "$@"
28+
else
29+
/bin/df -hT -x squashfs -x tmpfs
30+
fi
31+
}
32+
fi
33+
34+
alias scan='sudo nmap -sS -Pn -R -v -O -f'
35+
alias beep="echo -e '\a'; sleep 1; echo -e '\a'; sleep 1; echo -e '\a'"
36+
type -P colorls >/dev/null && alias ls='colorls --sort-dirs --gs'
37+
export DEBEMAIL="[email protected]"
38+
export DEBFULLNAME="Ira Abramov"
3939
fi

home/.bash.aliases.d/ira.video.sh

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22

33
# Get cracking on some demuxing
44

5-
function demuxaudio () {
6-
about 'Demux audio out of a .mov/.avi/.mp4 file.'
7-
group 'gif'
8-
param '1: MOV/AVI/MP4 file name(s)'
5+
function demuxaudio() {
6+
about 'Demux audio out of a .mov/.avi/.mp4 file.'
7+
group 'gif'
8+
param '1: MOV/AVI/MP4 file name(s)'
99

10-
for file ; do
10+
for file; do
1111

12-
local output_file="${file%.*}"
13-
local output_suffix
14-
output_suffix="$(mediainfo "$file" | grep "Format " | \
15-
tail -1 | awk '{print $3}' | tr '[:upper:]' '[:lower:]')"
16-
# Common names
17-
[[ $output_suffix == "opus" ]] && output_suffix="ogg"
12+
local output_file="${file%.*}"
13+
local output_suffix
14+
output_suffix="$(mediainfo "$file" | grep "Format " |
15+
tail -1 | awk '{print $3}' | tr '[:upper:]' '[:lower:]')"
16+
# Common names
17+
[[ $output_suffix == "opus" ]] && output_suffix="ogg"
1818

19-
ffmpeg -loglevel panic -i "${file}" -c:a copy -vn -sn "${output_file}.${output_suffix}"
19+
ffmpeg -loglevel panic -i "${file}" -c:a copy -vn -sn "${output_file}.${output_suffix}"
2020

21-
done
21+
done
2222
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
22
function parse_git_branch {
3-
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
3+
git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
44
}
55

66
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w \[\033[01;31m\]\$(parse_git_branch)\[\033[00m\]\$ "
77
export CLICOLOR=1
88
export LSCOLORS=ExFxBxDxCxegedabagacad
99

1010
function iterm2_print_user_vars() {
11-
iterm2_set_user_var gitBranch "$( (git branch 2> /dev/null) | grep '\*' | cut -c3-)"
11+
iterm2_set_user_var gitBranch "$( (git branch 2>/dev/null) | grep '\*' | cut -c3-)"
1212
}

0 commit comments

Comments
 (0)