diff --git a/.gitignore b/.gitignore index ee5cd2a..79422c8 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ vim/undo vim/undo/* config/openbox/lxde-rc.xml *.pyc +!bin diff --git a/README.md b/README.md index 404ff69..42c61bd 100644 --- a/README.md +++ b/README.md @@ -7,5 +7,5 @@ Various dotfiles and misc configs. Some of it is customized around my system set Installing ========== -There is an `install.sh` script that fasciliates with setup, however it's been a while since I did a full system setup and this script may not be fully complete. An alternative method is to manually symlink files in the root directory. OS specific configs are in their respective folders. +There is an `install.sh` script that facilitates the setup, however it's been a while since I did a full system setup and this script may not be fully complete. An alternative method is to manually symlink files in the root directory. OS specific configs are in their respective folders. diff --git a/aliases b/aliases index a71efc4..b35fb33 100644 --- a/aliases +++ b/aliases @@ -28,12 +28,23 @@ elif [[ "${platform,,}" == *'ming'* ]]; then # convert to lowercase then compare alias l='ls -ahg --color' alias ls='ls -ahg --color' - #alias rm='echo "use trash command instead!"' + alias rm='echo "use trash command instead!"' alias rmr='echo "use trash command instead!"' - alias trash='recycle-bin.exe ' - alias tt='trash ' + alias trash='remove_windows_file' + alias tt='remove_windows_file' + alias cgrep='cgrep.exe' fi +remove_windows_file() { + if [ -f "$1" ]; then + recycle-bin.exe "$1" + elif [ -d "$1" ]; then + recycle-bin.exe "$1" + else + echo "'$1' does not exist!" + fi +} + alias c='cd' alias c-='cd -' alias cd-='echo "Use c- instead"' @@ -145,14 +156,39 @@ alias vs='vagrant ssh' alias vu='vagrant up' alias vimrc='vim ~/.vimrc' alias weather='curl wttr.in/toronto' -alias yt-download='youtube-dl.exe -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s"' -alias yt8='youtube-dl.exe -f "137+140" -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" ' -alias yt-download-1080='youtube-dl.exe -f "137+140" -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" ' -alias yt-download-720='youtube-dl.exe -f "136+140" -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" ' -alias tw-download-60='youtube-dl.exe -f "1080p60" -o "%(upload_date)s-%(title)s-twitch-%(id)s.%(ext)s" ' -alias tw-download-720='youtube-dl.exe -f "720p-1" -o "%(upload_date)s-%(title)s-twitch-%(id)s.%(ext)s" ' -alias tw-download-4k='youtube-dl.exe -f "2160p" -o "%(upload_date)s-%(title)s-twitch-%(id)s.%(ext)s" ' -alias tw-download='youtube-dl.exe -f "1080p" -o "%(upload_date)s-%(title)s-twitch-%(id)s.%(ext)s" ' + +# Download YouTube videos +function dl_youtube_vid { + local format="$1" + local url="$2" + regexp="[[:blank:]]+" + if [[ $format == "" ]]; then + echo "Downloading default format" + youtube-dl.exe -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" $url + else + youtube-dl.exe -f "$format" -o "%(upload_date)s-%(title)s-youtube-%(id)s.%(ext)s" $url + fi +} +alias yt-download='dl_youtube_vid ""' +alias yt-download-1080='dl_youtube_vid "137+140"' +alias yt-download-720='dl_youtube_vid "136+140"' + +# Download Twitch videos +function dl_twitch_vid { + local format="$1" + local url="$2" + local dir=$(date '+%Y-%m-%d-%H-%M-%S') + mkdir -p $dir + cd $dir + rechat.exe -D $url + rm *.json + youtube-dl.exe -f "$format" -o "%(upload_date)s-%(title)s-twitch-%(id)s.%(ext)s" $url + cd .. +} +alias tw-download='dl_twitch_vid "1080p"' +alias tw-download-60='dl_twitch_vid "1080p60"' +alias tw-download-720='dl_twitch_vid "720p-1"' +alias tw-download-4k='dl_twitch_vid "2160p"' # Git diff --git a/bin/cgrep b/bin/cgrep deleted file mode 100644 index 69944ef..0000000 Binary files a/bin/cgrep and /dev/null differ diff --git a/bin/cgrep.exe b/bin/cgrep.exe deleted file mode 100644 index 26c8fa6..0000000 Binary files a/bin/cgrep.exe and /dev/null differ diff --git a/bin/cindex b/bin/cindex deleted file mode 100644 index 0d09edf..0000000 Binary files a/bin/cindex and /dev/null differ diff --git a/bin/cindex.exe b/bin/cindex.exe deleted file mode 100644 index 91c4ac1..0000000 Binary files a/bin/cindex.exe and /dev/null differ diff --git a/bin/csearch b/bin/csearch deleted file mode 100644 index e74627d..0000000 Binary files a/bin/csearch and /dev/null differ diff --git a/bin/csearch.exe b/bin/csearch.exe deleted file mode 100644 index f8fb105..0000000 Binary files a/bin/csearch.exe and /dev/null differ diff --git a/bin/pt.exe b/bin/pt.exe deleted file mode 100644 index 4a799b5..0000000 Binary files a/bin/pt.exe and /dev/null differ diff --git a/bin/recycle-bin.exe b/bin/recycle-bin.exe deleted file mode 100644 index 449f629..0000000 Binary files a/bin/recycle-bin.exe and /dev/null differ diff --git a/bin/symbolic-link b/bin/symbolic-link new file mode 100644 index 0000000..a203975 --- /dev/null +++ b/bin/symbolic-link @@ -0,0 +1,28 @@ +#!/bin/bash + +source "$HOME/.dotfiles/script_helpers/all.sh" + +cwd=$PWD +source_path="" +dest_path="" + +#echo "got $1 and $2 and $3" + +if [[ $1 ]]; then + source_path=$1 +else + printf "${BOLD}${YELLOW}Enter full path to source file/dir:\n${NORMAL}" + read -e source_path +fi + +if [[ $2 ]]; then + dest_path=$2 +else + printf "${BOLD}${YELLOW}Enter full path to symlink destination:\n${NORMAL}" + read -e dest_path +fi + +if [[ $3 ]]; then expand_symlinks=$3; else expand_symlinks=0; fi + +confirm_link=1 +link_file "$source_path" "$dest_path" $confirm_link $expand_symlinks diff --git a/windows/symbolic-link.sh b/bin/symbolic-link.sh similarity index 100% rename from windows/symbolic-link.sh rename to bin/symbolic-link.sh diff --git a/gitconfig b/gitconfig index b608219..07736fd 100644 --- a/gitconfig +++ b/gitconfig @@ -1,13 +1,15 @@ [include] path = ~/.gitconfig.platform [user] - name = Michael Campagnaro - email = mikecampo@gmail.com + name = Michael Campagnaro + email = mikecampo@gmail.com [merge] summary = true tool = vimdiff [core] excludesfile = ~/.gitignore + preloadindex = true + fscache = true [push] default = upstream [diff] @@ -29,11 +31,14 @@ old = red new = green [filter "lfs"] - clean = git-lfs clean %f - smudge = git-lfs smudge %f + clean = git-lfs clean -- %f + smudge = git-lfs smudge -- %f required = true + process = git-lfs filter-process [alias] lg = log --graph --pretty=format:'%Cred%h%Creset %C(yellow)%an [%cn]%d%Creset %s %Cgreen(%cr)%Creset' --date=relative - start = !git init && git commit --allow-empty -m \"Initial commit, mofuck\" + start = !git init && git commit --allow-empty -m \"Initial commit\" [rerere] enabled = true +[gc] + auto = 0 diff --git a/script_helpers/all.sh b/script_helpers/all.sh new file mode 100644 index 0000000..ca07a48 --- /dev/null +++ b/script_helpers/all.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +source_helpers="$HOME/.dotfiles/script_helpers" +source "$source_helpers/printing.sh" +source "$source_helpers/core.sh" +source "$source_helpers/platform.sh" +source "$source_helpers/file_ops.sh" + diff --git a/script_helpers/core.sh b/script_helpers/core.sh new file mode 100644 index 0000000..a78bb79 --- /dev/null +++ b/script_helpers/core.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Requires the printing.sh helper to be sourced. + +#--------------------------------------------------------------------------------------------------- +# API +#--------------------------------------------------------------------------------------------------- + +abort() { + error "\nAborting...\n" + exit 1 +} + diff --git a/script_helpers/file_ops.sh b/script_helpers/file_ops.sh index 14bb6ef..57cb9f4 100644 --- a/script_helpers/file_ops.sh +++ b/script_helpers/file_ops.sh @@ -1,41 +1,16 @@ #!/bin/bash -if which tput >/dev/null 2>&1; then - ncolors=$(tput colors) -fi -if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then - RED="$(tput setaf 1)" - GREEN="$(tput setaf 2)" - YELLOW="$(tput setaf 3)" - BLUE="$(tput setaf 4)" - BOLD="$(tput bold)" - NORMAL="$(tput sgr0)" -else - RED="" - GREEN="" - YELLOW="" - BLUE="" - BOLD="" - NORMAL="" -fi - -error() { - printf "${BOLD}${RED}$1${NORMAL}" -} - -log() { - msg="$1" - value="$2" - printf "@log ${BOLD}${YELLOW}$msg${GREEN}$value${NORMAL}\n" -} +# Requires the printing.sh helper to be sourced. +# Requires the platform.sh helper to be sourced. #--------------------------------------------------------------------------------------------------- # API #--------------------------------------------------------------------------------------------------- + +# Will return a symlink path in its expanded form. If the path's root is the +# home directory symbol "~" then it'll be replaced by the full home path. expand_path() { - # Expands a symlink path. If the root folder is the home directory symbol "~" then it'll be - # replaced by the full home path. local ret="$1" IFS="/" read -ra parts <<< "$ret" @@ -51,17 +26,19 @@ expand_path() { echo $ret } -windows_path() { - ret=$1 - - if [[ $(is_absolute_unix_path $ret) -eq 1 ]]; then - ret="${ret/\//}" - # Fix the drive name, e.g. c\foo becomes c:\foo - ret=$(sed 's,\([a-zA-Z]*\),\1:,' <<< "$ret") - fi - - ret="${ret////\\}" # replace unix path with windows path - echo $ret +unix_to_windows_path() { + ret=$1 + if [[ $(is_windows_path $ret) -eq 1 ]]; then + echo $ret + else + if [[ $(is_absolute_unix_path $ret) -eq 1 ]]; then + ret="${ret/\//}" + # Fix the drive name, e.g. c\foo becomes c:\foo + ret=$(sed 's,\([a-zA-Z]*\),\1:,' <<< "$ret") + fi + ret="${ret////\\}" # replace unix path with windows path + echo $ret + fi } windows_to_unix_path() { @@ -135,12 +112,108 @@ is_sym_file() { if [[ $1 =~ ^\.{1} ]]; then echo 1; else echo 0; fi } -# Will return false if the path has no slashes. is_windows_path() { if [[ ! $1 =~ \/+ ]]; then echo 1; else echo 0; fi } -# Will return false if the path has no slashes. is_unix_path() { echo $(! is_windows_path "$1") } + +path_has_a_space() { + regexp="[[:blank:]]+" + if [[ $1 =~ $regexp ]]; then echo 1; else echo 0; fi +} + +# Expands a path when it's not a symbolic link or an absolute drive path. +_clean_link_file_path() { + path=$1 + if [[ $(is_absolute_unix_path "$path") -eq 0 && $(is_sym_file "$path") -eq 0 ]]; then + path=$(expand_path "$path") + fi + echo $path +} + +# Creates a symlink. +# Requires an admin shell when running under Windows. +link_file() { + source_path=$1 + dest_path=$2 + require_confirmation=$3 + expand_symlinks=$4 + + os_is_windows is_windows + os_is_unix is_unix + + # @INSTEAD ESCAPE THE SPACES IN THE FINAL WINDOWS PATH + # @INSTEAD ESCAPE THE SPACES IN THE FINAL WINDOWS PATH + # @INSTEAD ESCAPE THE SPACES IN THE FINAL WINDOWS PATH + # @INSTEAD ESCAPE THE SPACES IN THE FINAL WINDOWS PATH + # @INSTEAD ESCAPE THE SPACES IN THE FINAL WINDOWS PATH + # @INSTEAD ESCAPE THE SPACES IN THE FINAL WINDOWS PATH + #https://stackoverflow.com/questions/1473981/how-to-check-if-a-string-has-spaces-in-bash-shell + #https://stackoverflow.com/questions/28256178/how-can-i-match-spaces-with-a-regexp-in-bash + + source_has_space=$(path_has_a_space "$source_path") + dest_has_space=$(path_has_a_space "$dest_path") + + debug=1 + if [[ $debug -eq 1 ]]; then + echo source path: $source_path + echo dest path: $dest_path + echo source has space: $source_has_space + echo dest has space: $dest_has_space + echo abs unix source: $(is_absolute_unix_path "$source_path") + echo abs unix dest: $(is_absolute_unix_path "$dest_path") + echo "require_confirmation? $require_confirmation" + echo "expand_symlinks? $expand_symlinks" + fi + + if [[ $expand_symlinks -eq 1 ]]; then + source_path=$(expand_path "$source_path") + dest_path=$(expand_path "$dest_path") + else + source_path=$(_clean_link_file_path "$source_path") + dest_path=$(_clean_link_file_path "$dest_path") + fi + + if [[ $debug -eq 1 ]]; then + echo "after source: $source_path" + echo "after dest: $dest_path" + fi + + # Verify that the source path exists. + ! test -d "$source_path" && ! test -e "$source_path" && error "Source path '$source_path' doesn't exist!" && abort + + # Verify that the dest path doesn't already exist. + test -d "$dest_path" && error "Dest folder '$dest_path' already exists!" && abort + test -e "$dest_path" && error "Dest file '$dest_path' already exists!" && abort + + if [[ $is_windows -eq 1 ]]; then + source_path=$(unix_to_windows_path "$source_path") + dest_path=$(unix_to_windows_path "$dest_path") + if [[ $source_has_space -eq 1 ]]; then source_path="\"$source_path\""; fi + if [[ $dest_has_space -eq 1 ]]; then dest_path="\"$dest_path\""; fi + link_cmd="cmd //c 'mklink $dest_path $source_path'" + else + if [[ $source_has_space -eq 1 ]]; then source_path="\"$source_path\""; fi + if [[ $dest_has_space -eq 1 ]]; then dest_path="\"$dest_path\""; fi + link_cmd="ln -sf $source_path $dest_path" + fi + + if [[ $require_confirmation -eq 1 ]]; then + echo "${BOLD}${BLUE}Will attempt to link ${GREEN}$source_path${BLUE} to ${GREEN}$dest_path${BLUE}" + printf "${BOLD}Enter 1 to proceed\n${YELLOW}> ${NORMAL}" + read confirm + if [[ $confirm != 1 ]]; then abort; fi + fi + + if [[ $debug -eq 1 ]]; then + echo Final source: $source_path + echo Final dest: $dest_path + echo Link cmd:: $link_cmd + fi + + eval $link_cmd +} + diff --git a/script_helpers/platform.sh b/script_helpers/platform.sh new file mode 100644 index 0000000..1873d1f --- /dev/null +++ b/script_helpers/platform.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +uname_s="$(uname -s)" +case "${uname_s}" in + Linux*) platform="LINUX" platform_os="LINUX";; + Darwin*) platform="MACOS" platform_os="MACOS";; + CYGWIN*) platform="CYGWIN" platform_os="WINDOWS";; + MINGW*) platform="MINGW" platform_os="WINDOWS";; + *) platform="UNKNOWN:${uname_s} platform_os="UNKNOWN_OS"" +esac + +#--------------------------------------------------------------------------------------------------- +# API +#--------------------------------------------------------------------------------------------------- + +os_is() { + declare -n _os_is=$1 + if [[ $platform_os == $2 ]]; then _os_is=1; else _os_is=0; fi +} + +shell_is() { + declare -n _shell_is=$1 + if [[ $platform == $2 ]]; then _shell_is=1; else _shell_is=0; fi +} + +shell_is_mingw() { declare -n _shell_ret=$1; shell_is _shell_ret "MINGW"; } +shell_is_cygwin() { declare -n _shell_ret=$1; shell_is _shell_ret "CYGWIN"; } + +os_is_windows() { declare -n _os_ret=$1; os_is _os_ret "WINDOWS"; } +os_is_linux() { declare -n _os_ret=$1; os_is _os_ret "LINUX"; } +os_is_macos() { declare -n _os_ret=$1; os_is _os_ret "MACOS"; } +os_is_unix() { + declare -n _os_ret=$1; + if [[ $platform_os == "LINUX" || $platform_os == "MACOS" ]]; then + _os_ret=1 + else + _os_ret=0 + fi +} + diff --git a/windows/bashrc b/windows/bashrc index 85f73cb..e751fa9 100644 --- a/windows/bashrc +++ b/windows/bashrc @@ -22,10 +22,14 @@ export TEMP=/tmp export TMPDIR=/tmp # Customize the shell prompt +in_git_work_tree() { + git rev-parse --is-inside-work-tree &> /dev/null +} + parse_git_branch() { - if [[ "$PWD" != "$HOME" ]]; then - git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' - fi + if in_git_work_tree; then + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' + fi } export PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] @ \w\[\033[33m\]\n$(parse_git_branch)\[\033[0;32m\]\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\]\[\033[0m\] ' diff --git a/windows/readme.md b/windows/readme.md index 4adea94..4a9dbed 100644 --- a/windows/readme.md +++ b/windows/readme.md @@ -45,13 +45,15 @@ Data="0x00000000” and verify that `which envsubst` reports back `/usr/bin/envsubst`. * Bug report is at https://github.com/Alexpux/MSYS2-packages/issues/735 * Map caps to left-ctrl using https://sharpkeys.codeplex.com/ +* Setup git completions for bash: + * `curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash` * Use symlink command `cmd //c 'mklink .name-of-dotfile drive:\path\to\file'`. * Symlink `~/.private-files` to the root directory containing `dev/`. * Symlink `~/.dev` to `~/.private-files/path/to/dev`. * Symlink `~/.dotfiles` to `~/.dev/path/to/dotfiles`. * Create `~/bin`. -* Symlink `$HOME/bin/sym` to `$HOME/.dotfiles/windows/symbolic-link.sh`. You can now use this to +* Symlink `$HOME/bin/sym` to `$HOME/.dotfiles/bin/symbolic-link`. You can now use this to do symlinks. * Symlink files in the dotfiles windows folder. * Symlink appropriate files in the root dotfiles directory. @@ -74,10 +76,10 @@ Data="0x00000000” ## Setting up Visual Studio -* Use the backed up VS2015 ISO. +* Use the backed up VS2015 ISO or download it from https://go.microsoft.com/fwlink/?LinkId=615448&clcid=0x409 * Pick a custom install directory, e.g. `/x/programs/Visual Studio 15` -* Make sure to not do a default install. You must select the C++ language support. -* Edit visual studio options. Open Debugging -> Symbols and add the path to your cached symbols. +* Select a custom install and check off the C++ language support. +* Once installed, open Visual Studio and go to `Tools` -> `Options`. Open `Debugging` -> `Symbols` and add the path to the cached symbols directory that you set up above under `Setup a symbol server`. ## Setting up Vim @@ -147,7 +149,10 @@ Data="0x00000000” ## Software +* Install `tree`: `pacman -S tree` + * Install Desktop Restore (http://www.midiox.com/index.htm?http://midiox.com/desktoprestore.htm) + * Install Android platform tools to get adb.exe: * Download Android commandline tools https://developer.android.com/studio/#downloads * Unzip to some location.