From 80ea8653c30ad3eb41b778287fb193e393b246d3 Mon Sep 17 00:00:00 2001 From: Kevin Mok Date: Wed, 5 Dec 2018 10:02:23 -0500 Subject: [PATCH] Wrote script to clean up LaTeX build files Used Shellcheck to change all my scripts to bash and lint them. Exported my scripts to $PATH. Fixed my liked Arch packages. --- aliases/zsh_aliases | 7 +- configs/i3/config | 4 +- dotfiles/vimrc | 29 ++++--- dotfiles/zshrc | 2 +- scripts/backup.sh | 3 +- scripts/{change-sink.sh => change-sink} | 8 +- scripts/install-arch-pkgs.sh | 7 +- scripts/{shortcuts.sh => sync-shortcuts} | 0 scripts/texclear | 40 +++++++++ setup-root.sh | 26 +----- setup.sh | 38 ++++----- txt/pacman-pkgs/aur-pkgs.txt | 2 + txt/pacman-pkgs/nzxt-pkgs.txt | 24 +++++- txt/pacman-pkgs/pacman-pkgs.txt | 104 +---------------------- txt/tex-build-files.txt | 23 +++++ 15 files changed, 149 insertions(+), 168 deletions(-) rename scripts/{change-sink.sh => change-sink} (71%) rename scripts/{shortcuts.sh => sync-shortcuts} (100%) create mode 100755 scripts/texclear create mode 100644 txt/tex-build-files.txt diff --git a/aliases/zsh_aliases b/aliases/zsh_aliases index 5db84af..d236741 100644 --- a/aliases/zsh_aliases +++ b/aliases/zsh_aliases @@ -39,7 +39,7 @@ function gpdf() { # for finding files by name function rf() { find . -name '$1' ; } # find text inside files -function rg() { grep -nr $1 * ; } +function rg() { grep -nr $1 ; } function cpd() { cp -avr $1 $2 ; } alias pk="pkill -f" @@ -122,7 +122,7 @@ alias vlh="alsamixer -c 2" # alias aptu="sudo apt upgrade" alias pc="sudo pacman -S" alias pcr="sudo pacman -Rs" -alias spc="pacman -Qqe > ~/linux-config/txt/pacman-pkgs/pacman-pkgs.txt" +alias xpc="pacman -Qqe > ~/linux-config/txt/pacman-pkgs/nzxt-pkgs.txt" # alias tri="trizen -S --noconfirm" alias tri="trizen -S" @@ -342,11 +342,14 @@ alias hs="$spv_dir/src/update-history.sh && hlg" # function svm() { mv $1 ~/.local/share/Steam/steamapps/common/Stardew\ Valley/Mods ; } # # }}} +alias shc="cs && shellcheck" + # }}} coding projs # # school {{{ # alias pdl="pdflatex" +alias tcl="texclear" # 343 alias ij="sudo ~/Downloads/idea/bin/idea.sh $silent" diff --git a/configs/i3/config b/configs/i3/config index d65667b..dac3fd3 100644 --- a/configs/i3/config +++ b/configs/i3/config @@ -458,8 +458,8 @@ font pango:Hack 11 # }}} mod key/font # # media keys {{{ # -bindsym $mod+d exec ~/linux-config/scripts/change-sink.sh dac -bindsym $mod+o exec ~/linux-config/scripts/change-sink.sh line-out +bindsym $mod+d exec ~/linux-config/scripts/change-sink dac +bindsym $mod+o exec ~/linux-config/scripts/change-sink line-out bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -c 0 sset Master 3+ bindsym XF86AudioLowerVolume exec --no-startup-id amixer -c 0 sset Master 3- diff --git a/dotfiles/vimrc b/dotfiles/vimrc index 2f13088..2e59457 100644 --- a/dotfiles/vimrc +++ b/dotfiles/vimrc @@ -37,12 +37,17 @@ autocmd Filetype css,htmldjango,html,tex,txt,markdown set tabstop=2 shiftwidth=2 autocmd BufNewFile,BufRead *.md set filetype=markdown autocmd Filetype markdown set textwidth=0 -autocmd BufWritePost key_*.txt !bash ~/linux-config/scripts/shortcuts.sh -" auto-reload vimrc when saved -augroup myvimrc - au! - au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif -augroup END +autocmd BufWritePost key_*.txt !sync-shortcuts +autocmd VimLeave *.tex !texclear % + +" " auto-reload vimrc {{{ " + +" augroup myvimrc + " au! + " au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif +" augroup END + +" " }}} auto-reload vimrc " " }}} commands for file types " @@ -75,15 +80,18 @@ Plug 'xolox/vim-misc' " automatically save buffers upon returning to normal mode Plug '907th/vim-auto-save' let g:auto_save = 1 - -" compile LaTeX PDF while writing the file -" Plug 'xuhdev/vim-latex-live-preview', { 'for': 'tex' } " provides various functionality for writing LaTeX in Vim Plug 'lervag/vimtex' au BufWritePost *.tex silent call Tex_RunLaTeX() au BufWritePost *.tex silent !pkill -USR1 xdvi.bin let g:vimtex_view_general_viewer = 'zathura' + let g:vimtex_quickfix_latexlog = { + \ 'overfull' : 0, + \ 'underfull' : 0, + \ 'global' : 0, + \ 'unused' : 0, + \} " auto-completion for various languages Plug 'Valloric/YouCompleteMe' @@ -159,6 +167,7 @@ map :make -C ~/Documents/resume cv map :AutoSaveToggle " map :LLPStartPreview map :VimtexCompile:VimtexView +" map :VimtexCompile nnoremap :set paste"+p:set nopaste " }}} function keys " @@ -221,7 +230,7 @@ nnoremap rv :source $MYVIMRC " replace in entire file nnoremap R q:i%s///g2F/i " sort lines -nnoremap s q:i.,.+sortFsi +nnoremap so q:i.,.+sortFsi " set syntax to shell (for dotfiles) nnoremap sh :set syn=sh " format current line diff --git a/dotfiles/zshrc b/dotfiles/zshrc index bc197f4..66f19e2 100644 --- a/dotfiles/zshrc +++ b/dotfiles/zshrc @@ -108,7 +108,7 @@ if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then fi # pywal -export PATH="${PATH}:${HOME}/.local/bin/" +export PATH="${PATH}:${HOME}/.local/bin/:${HOME}/linux-config/scripts" (cat ~/.cache/wal/sequences &) # keyboard delay/rate diff --git a/scripts/backup.sh b/scripts/backup.sh index 6b1f3bf..af2bf1d 100755 --- a/scripts/backup.sh +++ b/scripts/backup.sh @@ -4,9 +4,8 @@ backup_dest=/run/media/kevin/pc-backup/backups/nzxt # Labels for backup name -PC=${HOST} distro=arch datetime=$(date "+%m.%d-%H.%M") backupfile="$backup_dest/$datetime-$distro.tar.gz" -sudo tar -czpvf $backupfile --exclude=/lost+found --exclude=/mnt --exclude=/proc --exclude=/run --exclude=/sys / +sudo tar -czpvf "$backupfile" --exclude=/lost+found --exclude=/mnt --exclude=/proc --exclude=/run --exclude=/sys / diff --git a/scripts/change-sink.sh b/scripts/change-sink similarity index 71% rename from scripts/change-sink.sh rename to scripts/change-sink index 3273860..0311ef4 100755 --- a/scripts/change-sink.sh +++ b/scripts/change-sink @@ -1,18 +1,18 @@ #!/bin/bash #Device name variable -if [ $1 = "dac" ]; then +if [ "$1" = "dac" ]; then devicename="alsa_output.usb-FiiO_DigiHug_USB_Audio-01.analog-stereo" -elif [ $1 = "line-out" ]; then +elif [ "$1" = "line-out" ]; then devicename="alsa_output.pci-0000_00_14.2.analog-stereo" fi echo "$devicename" #change the default sink -pacmd "set-default-sink "$devicename"" +pacmd "set-default-sink $devicename" #move all inputs to the new sink for app in $(pacmd list-sink-inputs | sed -n -e 's/index:[[:space:]]\([[:digit:]]\)/\1/p'); do - pacmd "move-sink-input $app "$devicename"" + pacmd "move-sink-input $app $devicename" done diff --git a/scripts/install-arch-pkgs.sh b/scripts/install-arch-pkgs.sh index c46b356..d7d2320 100755 --- a/scripts/install-arch-pkgs.sh +++ b/scripts/install-arch-pkgs.sh @@ -1,4 +1,7 @@ #!/bin/bash -sudo pacman -Sy --needed - < ../txt/pacman-pkgs/pacman-pkgs.txt -sudo trizen -Sy --needed - < ../txt/pacman-pkgs/aur-pkgs.txt +# to-do: fix shellscript error? +pacman -Sy --needed - < ../txt/pacman-pkgs/pacman-pkgs.txt +trizen -Sy --needed - < ../txt/pacman-pkgs/aur-pkgs.txt +# sudo pacman -Sy --needed - < ../txt/pacman-pkgs/pacman-pkgs.txt +# sudo trizen -Sy --needed - < ../txt/pacman-pkgs/aur-pkgs.txt diff --git a/scripts/shortcuts.sh b/scripts/sync-shortcuts similarity index 100% rename from scripts/shortcuts.sh rename to scripts/sync-shortcuts diff --git a/scripts/texclear b/scripts/texclear new file mode 100755 index 0000000..9afb630 --- /dev/null +++ b/scripts/texclear @@ -0,0 +1,40 @@ +#!/bin/bash + +# Delete TeX build files when exiting from Vim or call on directory/directly to +# remove from there. + +ext_list="/home/kevin/linux-config/txt/tex-build-files.txt" +raw_exts="$(tr '\n' '|' < $ext_list)" +exts="(${raw_exts::-1})" +echo "$exts" +find_flags=(-maxdepth 1 -type f -regextype gnu-awk -regex) + +remove_build_files () { + regex=$2 + # echo find "$1" "${find_flags[@]}" "$regex" -delete -print + eval find "$1" "${find_flags[@]}" "$regex" -delete -print +} + +# when less than one argument, remove build files in current dir +if [[ "$#" -lt 1 ]]; then + regex=(\"^.*\\."$exts"$\") + remove_build_files . "${regex[0]}" +else + case "$1" in + # if tex file, remove only build files for that file + *.tex) + file=$(readlink -f "$1") + dir=$(dirname "$file") + base="${file%.*}" + regex=(\"^"$base"\\."$exts"$\") + remove_build_files "$dir" "${regex[0]}" ;; + # remove all build files in directory if given valid one + *) + if [[ -d "$1" ]]; then + regex=(\"^.*\\."$exts"$\") + remove_build_files "$1" "${regex[0]}" + else + printf "Give .tex file or directory as argument.\\n" + fi ;; + esac +fi diff --git a/setup-root.sh b/setup-root.sh index 09f7f48..6eb0da3 100755 --- a/setup-root.sh +++ b/setup-root.sh @@ -1,33 +1,15 @@ -#!/bin/zsh - -setup_marble=false +#!/bin/bash linux_config_dir=/home/kevin/linux-config dot_dir=$linux_config_dir/dotfiles -pc=$(hostname) # Get directory variables from script. # List of dotfiles I want to link to system. -dotfiles=(bashrc gitconfig inputrc imwheelrc vimrc Xmodmap Xresources zshrc) -cd $dot_dir -for dotfile in $dotfiles; do +dotfiles=(bashrc inputrc imwheelrc vimrc Xmodmap Xresources zshrc) +cd $dot_dir || exit +for dotfile in "${dotfiles[@]}"; do # Remove system dotfile. rm ~/."$dotfile" # Link dotfile in repository to system dotfile. cp "$dot_dir"/"$dotfile" ~/."$dotfile" done - -# marble mouse {{{ # - -if [[ "$setup_marble" = true ]]; then - config_file_name="10-evdev.conf" - sys_layout_file="/etc/X11/xorg.conf.d/$config_file_name" - config_dir="$linux_config_dir/x/marble-mouse" - - # Remove system file. - sudo rm -rf "$sys_layout_file" - # Link config file in repository to system config location. - sudo cp "$config_dir"/"$config_file_name" "$sys_layout_file" -fi - -# }}} marble mouse # diff --git a/setup.sh b/setup.sh index 0a4364a..3684114 100755 --- a/setup.sh +++ b/setup.sh @@ -1,6 +1,6 @@ -#!/bin/zsh +#!/bin/bash -setup_marble=true +# setup_marble=true # vars {{{ # @@ -8,7 +8,6 @@ linux_config_dir=/home/kevin/linux-config dot_dir=$linux_config_dir/dotfiles config_dir=$linux_config_dir/configs sys_config_dir=~/.config -pc=$(hostname) # }}} vars # @@ -19,8 +18,8 @@ pc=$(hostname) # Get directory variables from script. # List of dotfiles I want to link to system. dotfiles=(bashrc gitconfig inputrc imwheelrc vimrc xinitrc Xmodmap Xresources zshrc) -cd $dot_dir -for dotfile in $dotfiles; do +cd $dot_dir || exit +for dotfile in "${dotfiles[@]}"; do # Remove system dotfile. rm ~/."$dotfile" # Link dotfile in repository to system dotfile. @@ -43,30 +42,29 @@ ln -s "$dot_dir"/nvim "$orig_file" && echo "Setup Neovim config." # configs {{{ # -cd $linux_config_dir +cd $linux_config_dir || exit # List of config dirs in system config dir that I want to link to. config_dirs=(neofetch i3 i3blocks sam-i3blocks ranger) -# config_dirs=(neofetch i3 i3blocks ranger) -for cur_dir in $config_dirs; do +for cur_dir in "${config_dirs[@]}"; do # Remove system file. - rm -rf "$sys_config_dir"/"$cur_dir" + rm -rf ${sys_config_dir:?}/"$cur_dir" # Link config file in repository to system config location. ln -s "$config_dir"/"$cur_dir" "$sys_config_dir"/"$cur_dir" && echo "Linked $cur_dir config." done # }}} configs # -# marble mouse {{{ # +# # marble mouse {{{ # -if [[ "$setup_marble" = true ]]; then - config_file_name="10-evdev.conf" - sys_layout_file="/etc/X11/xorg.conf.d/$config_file_name" - config_dir="$linux_config_dir/x/marble-mouse" +# if [[ "$setup_marble" = true ]]; then + # config_file_name="10-evdev.conf" + # sys_layout_file="/etc/X11/xorg.conf.d/$config_file_name" + # config_dir="$linux_config_dir/x/marble-mouse" - # Remove system file. - sudo rm -rf "$sys_layout_file" - # Link config file in repository to system config location. - sudo ln -s "$config_dir"/"$config_file_name" "$sys_layout_file" && echo "Setup Marble mouse config." -fi + # # Remove system file. + # sudo rm -rf "$sys_layout_file" + # # Link config file in repository to system config location. + # sudo ln -s "$config_dir"/"$config_file_name" "$sys_layout_file" && echo "Setup Marble mouse config." +# fi -# }}} marble mouse # +# # }}} marble mouse # diff --git a/txt/pacman-pkgs/aur-pkgs.txt b/txt/pacman-pkgs/aur-pkgs.txt index 31ca725..eba2495 100644 --- a/txt/pacman-pkgs/aur-pkgs.txt +++ b/txt/pacman-pkgs/aur-pkgs.txt @@ -1,3 +1,5 @@ +discord +texlive-localmanager-git gscreenshot rxvt-unicode-pixbuf Hack NF diff --git a/txt/pacman-pkgs/nzxt-pkgs.txt b/txt/pacman-pkgs/nzxt-pkgs.txt index a43c855..7191c5c 100644 --- a/txt/pacman-pkgs/nzxt-pkgs.txt +++ b/txt/pacman-pkgs/nzxt-pkgs.txt @@ -8,16 +8,21 @@ broadcom-wl bzip2 chromium chromium-widevine +cloc cmake +cmatrix colordiff +compton coreutils cryptsetup device-mapper dhcpcd dialog diffutils +discord dmenu e2fsprogs +evince fakeroot feh file @@ -36,7 +41,7 @@ grep grub gscreenshot gzip -htop +htop-vim-git i3-gaps i3blocks i3status @@ -70,7 +75,9 @@ nvidia pacman patch pciutils +pdfgrep perl +pipes.sh pkgconf procps-ng psmisc @@ -79,6 +86,7 @@ python-dbus python-pip python-pywal python-setuptools +qdirstat ranger redshift reiserfsprogs @@ -86,16 +94,28 @@ rxvt-unicode-pixbuf s-nail sed shadow +shellcheck spotify st sudo sysfsutils sysstat +systemd-numlockontty systemd-sysvcompat tar texinfo +texlive-core +texlive-local-algorithmicx +texlive-local-algorithms +texlive-local-enumitem +texlive-local-hyperref +texlive-local-numprint +texlive-local-pgfplots +texlive-local-tkz-base +texlive-local-tkz-euclide +texlive-localmanager-git +trizen ttf-dejavu -udiskie udisks2 unzip usbutils diff --git a/txt/pacman-pkgs/pacman-pkgs.txt b/txt/pacman-pkgs/pacman-pkgs.txt index 01ff7c3..e593b8b 100644 --- a/txt/pacman-pkgs/pacman-pkgs.txt +++ b/txt/pacman-pkgs/pacman-pkgs.txt @@ -1,11 +1,7 @@ alsa-utils -autoconf automake -bash bc -bison broadcom-wl -bzip2 chromium chromium-widevine cloc @@ -13,159 +9,65 @@ cmake cmatrix colordiff compton -coreutils -cryptsetup -device-mapper dhcpcd dialog diffutils -discord dmenu -e2fsprogs evince fakeroot feh -file -filesystem findutils -flex fzf -gawk -gcc -gcc-libs -gdb -gettext git -glibc grep grub -gscreenshot -gzip htop-vim-git i3-gaps i3blocks i3status imwheel -inetutils -iniparser -iproute2 -iputils -jfsutils less -lib32-nvidia-utils -licenses linux linux-firmware linux-headers -logrotate lolcat lsof -lvm2 make -man-db -man-pages -mdadm -nano neofetch neovim netctl noto-fonts ntfs-3g -nvidia pacman -patch -pciutils pdfgrep perl pipes.sh -pkgconf -procps-ng -psmisc pulseaudio python-dbus python-pip python-pywal python-setuptools +qdirstat ranger redshift -reiserfsprogs rxvt-unicode-pixbuf -s-nail sed -shadow +shellcheck spotify st sudo -sysfsutils -sysstat systemd-numlockontty -systemd-sysvcompat tar texinfo +texlive-core trizen ttf-dejavu udisks2 unzip -usbutils -util-linux vi w3m -which wireless_tools wpa_supplicant xclip -xf86-input-evdev -xf86-input-keyboard -xf86-input-mouse -xf86-input-synaptics -xf86-input-vmmouse -xf86-input-void -xf86-video-amdgpu -xf86-video-ati -xf86-video-dummy -xf86-video-fbdev -xf86-video-intel -xf86-video-nouveau -xf86-video-openchrome -xf86-video-qxl -xf86-video-vesa -xf86-video-vmware -xf86-video-voodoo -xfsprogs -xorg-bdftopcf -xorg-iceauth -xorg-luit -xorg-mkfontdir -xorg-mkfontscale -xorg-server -xorg-sessreg -xorg-smproxy -xorg-x11perf -xorg-xbacklight -xorg-xcmsdb -xorg-xcursorgen -xorg-xdpyinfo -xorg-xdriinfo -xorg-xev -xorg-xgamma -xorg-xhost -xorg-xinit -xorg-xinput -xorg-xkbevd -xorg-xkbutils -xorg-xkill -xorg-xlsatoms -xorg-xlsclients -xorg-xpr -xorg-xprop -xorg-xrandr -xorg-xrefresh -xorg-xset -xorg-xsetroot -xorg-xvinfo -xorg-xwd -xorg-xwininfo -xorg-xwud zathura -zathura-pdf-poppler zsh diff --git a/txt/tex-build-files.txt b/txt/tex-build-files.txt new file mode 100644 index 0000000..29753ea --- /dev/null +++ b/txt/tex-build-files.txt @@ -0,0 +1,23 @@ +4tc +aux +bak +bbl +bcf +blg +fdb_latexmk +fls +lof +log +nav +out +pyc +pyo +run\\.xml +snm +swp +synctex\\(busy\\) +synctex\\.gz +tmp +toc +vrb +xref