@ -1,31 +1,102 @@ | |||
#!/bin/bash | |||
[[ -f ~/.bashrc ]] && . ~/.bashrc | |||
set -o vi | |||
bind -m vi-insert "\C-l":clear-screen | |||
# if running bash | |||
if [ -n "$BASH_VERSION" ]; then | |||
# include .bashrc if it exists | |||
if [ -f "$HOME/.bashrc" ]; then | |||
. "$HOME/.bashrc" | |||
shopt -s extglob | |||
HISTSIZE= | |||
HISTFILESIZE= | |||
export EDITOR='nvim' | |||
export GIT_AUTHOR_NAME="Tovi Jaeschke-Rogers" | |||
export GIT_AUTHOR_EMAIL="tovi@tovijaeschke.xyz" | |||
export GIT_COMMITTER_NAME="Tovi Jaeschke-Rogers" | |||
export GIT_COMMITTER_EMAIL="tovi@tovijaeschke.xyz" | |||
export LESS='-R' | |||
export LESSOPEN='|~/.lessfilter %s' | |||
if [[ $(uname) != "Linux" ]]; then | |||
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash" || true | |||
export HOMEBREW_NO_INSTALL_CLEANUP=1 | |||
export GIT_AUTHOR_EMAIL="tovi.jaeschke-rogers@thirty4.com" | |||
export GIT_COMMITTER_EMAIL="tovi.jaeschke-rogers@thirty4.com" | |||
mount-hdd() { | |||
if [ -z $1 ]; then | |||
sudo umount /dev/disk2s1 && sudo /usr/local/bin/ntfs-3g /dev/disk2s1 /Volumes/NTFS -olocal -oallow_other | |||
else | |||
sudo umount /dev/$1 && sudo /usr/local/bin/ntfs-3g /dev/$1 /Volumes/NTFS -olocal -oallow_other | |||
fi | |||
fi | |||
} | |||
export GOPATH="$HOME/code/go" | |||
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/share/games:/usr/local/sbin:/usr/sbin:/sbin:~/.local/bin:/usr/local/go/bin:$GOPATH/bin" | |||
fi | |||
# set PATH so it includes user's private bin if it exists | |||
if [ -d "$HOME/.local/bin" ] ; then | |||
PATH="$PATH:$(du "$HOME/.local/bin/" | cut -f2 | tr '\n' ':')" | |||
PATH="$PATH:$(du "$HOME/.local/bin/" | cut -f2 | tr '\n' ':')$HOME/.composer/vendor/bin" | |||
fi | |||
export TERMINAL='st' | |||
export EDITOR='vim' | |||
export PAGER='less' | |||
export BROWSER='firefox' | |||
source ~/.config/aliasrc | |||
parse_git_branch() { | |||
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |||
} | |||
export PS1=" \[\033[0;36m\]\t \[\033[0;35m\]\u\[\033[0;32m\]@\[\033[0;34m\]\h \[\033[32m\]\W\[\033[33m\]\$(parse_git_branch)\[\033[31m\] \n$\[\033[00m\] " | |||
mkcd() { | |||
if [ ! -d "$1" ]; then | |||
mkdir -p "$1" && cd "$1" | |||
elif [ -d "$1" ]; then | |||
cd "$1" | |||
else | |||
echo "Error" | |||
fi | |||
} | |||
# Go up directory structures | |||
up() { | |||
cd $(printf "%0.0s../" $(seq 1 $1)); | |||
} | |||
git() { | |||
if [[ $@ == "mergetool" ]]; then | |||
command git mergetool --no-gui | |||
else | |||
command git $@ | |||
fi | |||
} | |||
# git branch -vv | grep 'gone\]' | awk ' { print $1 }' | xargs -p git branch -d | |||
git-prune() { | |||
if [[ $@ == "--apply" ]]; then | |||
command git branch --merged develop | grep -vEw "develop$|master$" | xargs git branch -d | |||
else | |||
echo "Run \"git prune --apply\" to delete the following branches:" | |||
command git branch --merged develop | grep -vEw "develop$|master$" | |||
fi | |||
} | |||
color-diff() { | |||
if [ -z ${1+x} ] || [ -z ${2+x} ]; then | |||
echo "Usage: color-diff dir1/ dir2/" | |||
return | |||
fi | |||
diff -bur $1 $2 | colordiff | less | |||
} | |||
export NVM_DIR="$HOME/.nvm" | |||
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm | |||
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" | |||
export PULSE_PROP="filter.want=echo-cancel" | |||
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/cuda/lib64" | |||
export CUDA_HOME="/opt/cuda" | |||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion | |||
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx | |||
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh" | |||
eval "$(thefuck --alias)" |
@ -1,19 +1,23 @@ | |||
$include /etc/inputrc | |||
set editing-mode vi | |||
$if mode=vi | |||
set completion-ignore-case on | |||
set show-mode-in-prompt on | |||
set vi-ins-mode-string \1\e[6 q\2 | |||
set vi-cmd-mode-string \1\e[2 q\2 | |||
set keymap emacs | |||
"\C-x\C-r": re-read-init-file | |||
"\e[A": history-search-backward | |||
"\e[B": history-search-forward | |||
"\e[C": forward-char | |||
"\e[D": backward-char | |||
set keymap vi-command | |||
# these are for vi-command mode | |||
Control-l: clear-screen | |||
Control-a: beginning-of-line | |||
"\C-x\C-r": re-read-init-file | |||
"\e[A": history-search-backward | |||
"\e[B": history-search-forward | |||
"\e[C": forward-char | |||
"\e[D": backward-char | |||
set keymap vi-insert | |||
# these are for vi-insert mode | |||
Control-l: clear-screen | |||
Control-a: beginning-of-line | |||
"\C-x\C-r": re-read-init-file | |||
"\e[A": history-search-backward | |||
"\e[B": history-search-forward | |||
"\e[C": forward-char | |||
"\e[D": backward-char | |||
$endif |
@ -0,0 +1,169 @@ | |||
#!/bin/bash | |||
# Variables | |||
blog_dir=~/repos/blog-cms | |||
check() { | |||
if [ "$EUID" -ne 0 ] | |||
then | |||
echo "Please run as root" | |||
exit | |||
fi | |||
} | |||
confirm() { | |||
confirmvar="" | |||
while [[ "$confirmvar" == "" ]] | |||
do | |||
read -p "y/n/q: " confirmvar | |||
if [ "${confirmvar}" == "y" ] | |||
then | |||
echo true | |||
elif [ "${confirmvar}" == "n" ] | |||
then | |||
echo false | |||
fi | |||
done | |||
} | |||
newpost() { | |||
c=false | |||
while [[ ${c} == false ]] | |||
do | |||
read -p "Title: " title | |||
echo -e "Subject 1:\n\t0 - no subject\n\t1 - Programming\n\t2 - Pentesting\n\t3 - Personal" | |||
sub1=$(subjectselect) | |||
echo -e "Subject 1:\n\t0 - no subject\n\t1 - Programming\n\t2 - Pentesting\n\t3 - Personal" | |||
sub2=$(subjectselect) | |||
echo -e "Title: ${title}\nSubject 1: ${sub1}\nSubject 2: ${sub2}\n\nAre you sure?\n" | |||
c=$(confirm) | |||
done | |||
dirname=$(echo ${title} | sed 's/\ /_/g') | |||
mkdir -p ${blog_dir}/posts/${dirname}/static | |||
cd ${blog_dir}/posts/${dirname} | |||
echo ${title} >> title | |||
echo ${sub1} >> .sub1 | |||
echo ${sub2} >> .sub2 | |||
touch {intro.html,body.html} | |||
pwd | |||
ls -al | |||
} | |||
subjectselect() { | |||
read -p "0/1/2/3: " tmpvar | |||
if [ "$tmpvar" == "1" ] | |||
then | |||
echo "Programming" | |||
elif [ "$tmpvar" == "2" ] | |||
then | |||
echo "Pentesting" | |||
elif [ "$tmpvar" == "3" ] | |||
then | |||
echo "Personal" | |||
elif [ "$tmpvar" == "0" ] | |||
then | |||
echo "" | |||
fi | |||
} | |||
listandReturn() { printf "Listing contents of %s.\\n" "$1" | |||
ls -rc "$1" | awk -F '/' '{print $NF}' | nl | |||
read -erp "Pick an entry by number to $2, or press ctrl-c to cancel. " number | |||
chosen="$(ls -rc "$1" | nl | grep -w "$number" | awk '{print $2}')" | |||
basefile="$(basename "$chosen")" && base="${basefile%.*}" ;} | |||
upload() { | |||
#check | |||
listandReturn ${blog_dir}/posts | |||
#cd ${blog_dir}/posts/${basefile} | |||
titlevar=$(cat ${blog_dir}/posts/${basefile}/title) | |||
subvar1=$(cat ${blog_dir}/posts/${basefile}/.sub1) | |||
subvar2=$(cat ${blog_dir}/posts/${basefile}/.sub2) | |||
echo "Add intro pic?" | |||
if [[ $(confirm) == true ]] | |||
then | |||
listandReturn ${blog_dir}/posts/${basefile}/static/ | |||
picvar=${basefile} | |||
fi | |||
echo -n Mysql password: | |||
read -s sqlpassword | |||
scp ${blog_dir}/posts/${basefile}/{intro.html,body.html} root@tovijaeschke.xyz:/var/lib/mysql-files/ | |||
scp ${blog_dir}/posts/${basefile}/static/* root@tovijaeschke.xyz:/usr/share/nginx/personal/static/ | |||
if [[ "$picvar" == "" ]] | |||
then | |||
ssh root@tovijaeschke.xyz "chown mysql:mysql /var/lib/mysql-files/* && | |||
chmod go+rw /var/lib/mysql-files/* && | |||
mysql -u root -p${sqlpassword} -D PersonalWebsite -e \"INSERT INTO Posts (subject,subject2,title,intro,body) VALUES ('${subvar1}', '${subvar2}', '${titlevar}', LOAD_FILE('/var/lib/mysql-files/intro.html'), LOAD_FILE('/var/lib/mysql-files/body.html'));\"" | |||
else | |||
ssh root@tovijaeschke.xyz "chown mysql:mysql /var/lib/mysql-files/* && | |||
chmod go+rw /var/lib/mysql-files/* && | |||
mysql -u root -p${sqlpassword} -D PersonalWebsite -e \"INSERT INTO Posts (subject,subject2,title,pic,intro,body) VALUES ('${subvar1}', '${subvar2}', '${titlevar}', '${picvar}', LOAD_FILE('/var/lib/mysql-files/intro.html'), LOAD_FILE('/var/lib/mysql-files/body.html'));\"" | |||
fi | |||
} | |||
preview() { | |||
mkdir -p /tmp/preview | |||
cp -r ${blog_dir}/.preview/* /tmp/preview/ | |||
listandReturn ${blog_dir}/posts | |||
title=$(cat ${blog_dir}/posts/${basefile}/title | tr -d '\n') | |||
intro=$(cat ${blog_dir}/posts/${basefile}/intro.html | tr -d '\n') | |||
body=$(cat ${blog_dir}/posts/${basefile}/body.html | tr -d '\n') | |||
cp -r ${blog_dir}/posts/${basefile}/static/ /tmp/preview | |||
sed -i .bak 's|TITLE_PREVIEW|'"${title}"'|g' /tmp/preview/post.html | |||
sed -i .bak 's|INTRO_PREVIEW|'"${intro}"'|g' /tmp/preview/post.html | |||
sed -i .bak 's|BODY_PREVIEW|'"${body}"'|g' /tmp/preview/post.html | |||
if [[ $(uname) == "Linux" ]]; then | |||
firefox /tmp/preview/post.html | |||
else | |||
open -a firefox -g /tmp/preview/post.html | |||
fi | |||
} | |||
deletedraft() { | |||
echo "Which draft would you like to delete?" | |||
listandReturn ${blog_dir}/posts | |||
echo "Are you sure you want to delete \"$(cat ${blog_dir}/posts/${basefile}/title)?\"" | |||
c=$(confirm) | |||
if [ ${c} != false ] | |||
then | |||
rm -rf ${blog_dir}/posts/${basefile} | |||
fi | |||
} | |||
deletepost() { | |||
echo -n Mysql password: | |||
read -s sqlpassword | |||
echo -e "\nWhich post would you like to delete?" | |||
ssh root@tovijaeschke.xyz "mysql -u root -p${sqlpassword} -D PersonalWebsite -B --disable-column-names -e \"SELECT id,title FROM Posts;\"" | |||
read -p "\nWhich post would you like to delete?" post | |||
ssh root@tovijaeschke.xyz "mysql -u root -p${sqlpassword} -D PersonalWebsite -e \"DELETE FROM Posts WHERE id=${post};\" && \ | |||
post=\$(mysql -B -u root -p${sqlpassword} -D PersonalWebsite --disable-column-names -e \"SELECT MAX(id) FROM Posts;\") && \ | |||
mysql -u root -p${sqlpassword} -D PersonalWebsite -e \"ALTER TABLE Posts AUTO_INCREMENT=\$post;\"" | |||
} | |||
helpmsg() { | |||
printf "\nBLOG UPLOAD SCRIPT\n\n\tn - new draft\n\tp - preview post\n\tu - upload post\n\tdd - delete draft\n\tdp - delete post\n\th - help message\n\n" | |||
} | |||
case "$1" in | |||
n*) newpost ;; | |||
p*) preview ;; | |||
u*) upload ;; | |||
dd*) deletedraft ;; | |||
dp*) deletepost ;; | |||
h*) helpmsg ;; | |||
*) helpmsg ;; | |||
esac |
@ -1,28 +0,0 @@ | |||
#!/bin/bash | |||
# Dependencies are xclip and xorg-xprop. | |||
# qrencode required for qrcode generation. | |||
# groff/zathura required for man pages. | |||
prim="$(xclip -o)"; [ -z "$prim" ] && exit | |||
PID=$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep -m 1 PID | cut -d " " -f 3) | |||
PID=$(echo "$(pstree -lpA "$PID" | tail -n 1)" | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g') | |||
cd "$(readlink /proc/"$PID"/cwd)" | |||
[[ "${prim}" == *"~"* ]] && prim=$(echo "~/go/src/gitlab.com/tovijaeschke/website" | sed 's@~@'"$HOME"'@g') | |||
[ -f "$prim" ] && xdg-open "$prim" && exit | |||
[ -d "$prim" ] && st -c "$prim" && exit | |||
websearch() { "$BROWSER" "https://duckduckgo.com/?q=$@" ;} | |||
wikipedia() { "$BROWSER" "https://en.wikipedia.org/wiki/$@" ;} | |||
wiktionary() { "$BROWSER" "https://en.wiktionary.org/wiki/$@" ;} | |||
piratebay() { "$BROWSER" "https://piratebays.fi/s/?q=$@" ;} | |||
maps() { "$BROWSER" "https://www.openstreetmap.org/search?query=$@" ;} | |||
ebay() { "$BROWSER" "https://www.ebay.com/sch/$@" ;} | |||
echo "$prim" | grep "^.*\.[A-Za-z]\+.*" >/dev/null && gotourl() { "$BROWSER" "$@" ;} | |||
echo "$prim" | grep "^.*@.*\.[A-Za-z]\+$" >/dev/null && email() { xdg-email "$@" ;} | |||
command -v qrencode >/dev/null && qrcode() { qrencode "$@" -s 10 -o /tmp/qr.png && xdg-open /tmp/qr.png ;} | |||
man -k "^$prim$" >/dev/null && manual() { man -Tpdf "$prim" | zathura - ;} | |||
func="$(declare -F | awk '{print $3}' | dmenu -p "Plumb $prim to?" -i -l 15)" | |||
[ -z "$func" ] || "$func" "$prim" |
@ -1,4 +0,0 @@ | |||
#!/bin/bash | |||
notify-send "Changing wallpaper" | |||
feh --bg-fill ~/pix/cyberpunk/$(ls ~/pix/cyberpunk | shuf -n 1) |
@ -1,8 +0,0 @@ | |||
#!/bin/bash | |||
case "$1" in | |||
*.asm) nasm -f elf64 "$1" && ld "${1%.*}".o -o "${1%.*}"; rm "${1%.*}".o ;; | |||
*.c) gcc "$1" -o "${1%.*}" ;; | |||
*.go) go build "$1" ;; | |||
Makefile) make ;; | |||
esac |
@ -1,9 +0,0 @@ | |||
#!/bin/bash | |||
intern=LVDS-1 | |||
extern=VGA-1 | |||
if xrandr | grep "$extern connected"; then | |||
xrandr --output ${extern} --auto --right-of ${intern} | |||
else | |||
xrandr --output ${extern} --off --output ${intern} --auto | |||
fi |
@ -1,25 +0,0 @@ | |||
#!/bin/bash | |||
if [ -f $1 ] ; then | |||
# NAME=${1%.*} | |||
# mkdir $NAME && cd $NAME | |||
case $1 in | |||
*.tar.bz2) tar xvjf ../$1 ;; | |||
*.tar.gz) tar xvzf ../$1 ;; | |||
*.tar.xz) tar xvJf ../$1 ;; | |||
*.lzma) unlzma ../$1 ;; | |||
*.bz2) bunzip2 ../$1 ;; | |||
*.rar) unrar x -ad ../$1 ;; | |||
*.gz) gunzip ../$1 ;; | |||
*.tar) tar xvf ../$1 ;; | |||
*.tbz2) tar xvjf ../$1 ;; | |||
*.tgz) tar xvzf ../$1 ;; | |||
*.zip) unzip ../$1 ;; | |||
*.Z) uncompress ../$1 ;; | |||
*.7z) 7z x ../$1 ;; | |||
*.xz) unxz ../$1 ;; | |||
*.exe) cabextract ../$1 ;; | |||
*) echo "extract: '$1' - unknown archive method" ;; | |||
esac | |||
else | |||
echo "$1 - file does not exist" | |||
fi |
@ -1,10 +0,0 @@ | |||
#!/bin/bash | |||
if [ $(pgrep xautolock) ] | |||
then | |||
killall xautolock | |||
notify-send "🔓 Turning off xautolock" | |||
else | |||
xautolock -time 10 -locker slock & | |||
notify-send "🔒 Turning on xautolock" | |||
fi |
@ -1,4 +0,0 @@ | |||
#!/bin/bash | |||
pactl set-sink-volume @DEFAULT_SINK@ -5% | |||
vol=$(amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print $2 }') | |||
notify-send -t 500 "Volume: ${vol}" |
@ -1,4 +0,0 @@ | |||
#!/bin/bash | |||
pactl set-sink-volume @DEFAULT_SINK@ +5% | |||
vol=$(amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print $2 }') | |||
notify-send -t 500 "Volume: ${vol}" |
@ -1,14 +0,0 @@ | |||
#!/bin/bash | |||
listandReturn() { | |||
printf "Listing contents of %s.\\n" "$1" | |||
ls -rc "$1" | awk -F '/' '{print $NF}' | nl | |||
read -erp "Pick an entry by number to $2, or press ctrl-c to cancel. " number | |||
chosen="$(ls -rc "$1" | nl | grep -w "$number" | awk '{print $2}')" | |||
basefile="$(basename "$chosen")" && base="${basefile%.*}" | |||
} | |||
listandReturn ~/.openvpn/UDP\ 1194\ Normal/ | |||
sudo openvpn --config ~/.openvpn/UDP\ 1194\ Normal/${basefile} |