Skip to content

Commit

Permalink
dotfiles | Minor changes and updates (#4)
Browse files Browse the repository at this point in the history
* Update .aliases for macos

* Add dotnet helper script

* Update and test helper scripts.

* Update dotnet helper

* Reduce plugings to simplify initial vim settings

* Add support for Powerline fonts.
  • Loading branch information
nicholashoule authored Oct 23, 2022
1 parent 5421a31 commit bc463cc
Show file tree
Hide file tree
Showing 16 changed files with 338 additions and 151 deletions.
90 changes: 48 additions & 42 deletions home/.aliases
Original file line number Diff line number Diff line change
@@ -1,81 +1,87 @@
# aliases
# https://zsh.sourceforge.io/Intro/intro_8.html

# Detect which `ls` flavor is in use
if ls --color > /dev/null 2>&1; then
colorflag='--color=always' # GNU ls
else
colorflag="-G" # OS X ls
fi

# Vim aliases & helpers
alias vi='vim' # Ensure Vi IMproved
alias PluginInstall="vim +PluginInstall +qall" # Quick PluginInstall
alias PluginClean='vim +Pluginclean +qall' # Quick PluginClean

# Commands
# Canonical hex dump; some systems have this symlinked
command -v hd > /dev/null || alias hd="hexdump -C"
# macOS has no md5sum, so use md5 as a fallback
command -v md5sum > /dev/null || alias md5sum="md5"
# macOS has no sha1sum, so use shasum as a fallback
command -v sha1sum > /dev/null || alias sha1sum="shasum"

# Functions
## f:hgrep, History with grep
hgrep () { fc -Dlim "*$@*" 1 }
## f:sshKeysum, Determine the ssh-keyscan checksum wtih a Base64 encoded padded output
sshKeysum () { local chksum="${2:-sha256sum}"; for key in $(ssh-keyscan "${1}" 2>/dev/null | awk '{print $3}'); do echo -n "${key}" | base64 -d | eval "${chksum}" -b | xxd -r -p | base64; done }
## f:pubip, Get pubiic IP address
## Info: https://checkip.amazonaws.com, https://ipapi.co/ip/
publicip () { local ntwkhost="${1:-https://checkip.amazonaws.com}"; curl "${ntwkhost}" }
localip () { local ntwkint="${1:-en0}"; ipconfig getifaddr "${ntwkint}" }
allips () { ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }' }

# Aliases
# Vim, Tmux & helpers
alias vi='vim' # Ensure Vi IMproved
alias PluginInstall="vim +PluginInstall +qall" # Quick PluginInstall
alias PluginClean='vim +Pluginclean +qall' # Quick PluginClean
alias tmuxa='tmux attach -d -t'

# General
alias sudo='sudo ' # Enable aliases to be sudo'ed
alias tree='tree -C' # Pretty color tree
alias path='echo -e ${PATH//:/\\n}' # Pretty path

# directory listings
alias ls="command ls -hF ${colorflag}" # Always use color output for `ls`
alias l="ls -lF ${colorflag}" # List all files colorized in long format
alias l.="ls -d .* ${colorflag}"
alias ll="ls -aF ${colorflag}"
alias la="ls -laF ${colorflag}" # List all files colorized in long format, including dot files
alias lsd="ls -lF ${colorflag} | grep --color=never '^d'" # List only directories
alias dir="ls ${colorflag}--format=vertical"
alias vdir="ls ${colorflag} --format=long"
alias sudo='sudo ' # Enable aliases to be sudo'ed
alias tree='tree -C' # Pretty color tree
alias paths="echo -e '${PATH//:/\\n}'" # Pretty paths

# Listings
alias l="ls -lF" # List all files in long format
alias ll="ls -aF" # List all files in long format with dotfiles
alias la="ls -laF" # List all files in long format, including dot files
alias l.="ls -d .*" # List all dot directories and files
alias llsd="ls -lF | grep '^d'" # List only directories
alias llsf="ls -lF | grep '^-'" # List only files
alias ldirs="print -rl -- *(/)" # List directories
alias adirs="print -rl -- *(D/)" # List directories with hidden

# Shortcuts
alias dl="cd ~/Downloads"
alias dt="cd ~/Desktop"
alias cdl="cd ~/Downloads"
alias cdt="cd ~/Desktop"
alias hist="history"
alias timer='echo "Timer started. Stop with Ctrl-C." && $(time cat)'

# Tmux aliases
alias tmuxa='tmux attach -d -t'

# Git aliases
# Git
alias githash='git rev-parse --verify HEAD | cut -b 1-8'

# IP addresses
alias pubip='curl https://checkip.amazonaws.com'
alias localip="ipconfig getifaddr en0"
alias ips="ifconfig -a | grep -o 'inet6\? \(addr:\)\?\s\?\(\(\([0-9]\+\.\)\{3\}[0-9]\+\)\|[a-fA-F0-9:]\+\)' | awk '{ sub(/inet6? (addr:)? ?/, \"\"); print }'"

# Flush Directory Service cache
alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder"
# IP addresses & DNS
alias pubip=publicip
alias locip=localip
alias ips=allips

# View HTTP traffic
#alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
#alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""

# One of @janmoesen ProTips
for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
alias "$method"="lwp-request -m '$method'"
alias "${method}"="lwp-request -m ${method}"
done

# Alias scripting one-liners
# URL-encode strings
alias urlencode='python3 -c "import sys, urllib.parse as ul; print(ul.quote_plus(sys.argv[1]));"'

# MacOS Helpers
# OS, MacOS Helpers
# Software Updates, and update installed Ruby gems, Homebrew, npm, and their installed packages
alias update='sudo softwareupdate -i -a && brew update && brew upgrade --quiet && brew cleanup'

# Delete `.DS_Store` files
# Delete .DS_Store files
alias cleanupds="find . -type f -name '*.DS_Store' -ls -delete"

# Remove system logs and empty the Trash on all mounted volumes
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl"
#alias emptytrash="osascript -e 'if trashSize > \"0\" then tell application \"Finder\" to empty trash'"
alias emptytrash="osascript -e 'tell application \"Finder\" to empty trash'"

# Flush Directory Service cache
alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder"

# Show/hide hidden files in Finder
alias dotfilesshow="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
Expand Down
17 changes: 17 additions & 0 deletions home/.dotnet/completion.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# zsh parameter completion for the dotnet CLI
# https://learn.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete#zsh
_dotnet_zsh_complete() {
local completions=("$(dotnet complete "${words}")")

# If the completion list is empty, just continue with filename selection
if [ -z "${completions}" ]
then
_arguments '*::arguments: _normal'
return
fi

# This is not a variable assigment, don't remove spaces!
_values = "${(ps:\n:)completions}"
}

compdef _dotnet_zsh_complete dotnet
1 change: 1 addition & 0 deletions home/.dotnet/path.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export PATH="${0:A:h}:${PATH}"
85 changes: 85 additions & 0 deletions home/.dotnet/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Dotnet

## macOS

[Dotnet - macOS (Download)](https://dotnet.microsoft.com/en-us/download)

###### PATH

```
cat << EOF >> ~/.zshrc
# Dotnet
DOTNET_ROOT="${HOME}/.dotnet"
DOTNET_INSTALL_DIR="${HOME}/.dotnet"
PATH="\${PATH}:${DOTNET_ROOT}:${DOTNET_INSTALL_DIR}"
export DOTNET_ROOT DOTNET_INSTALL_DIR PATH
EOF
```

##### dotnet-install

[Dotnet - additional-tools (dotnet-install)](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script)

###### CLI

```
dotnet-install -h
```

```
...
Install Location:
Location is chosen in following order:
- --install-dir option
- Environmental variable DOTNET_INSTALL_DIR
- ${HOME}/.dotnet
```

##### dotnet-core-uninstall

[Dotnet - additional-tools ()](https://learn.microsoft.com/en-us/dotnet/core/additional-tools/uninstall-tool?tabs=macos)

###### CLI

```
dotnet-core-uninstall -h
```

```
...
Commands:
list List .NET Core SDKs or Runtimes that can be removed with this tool.
dry-run, whatif <VERSION> Display .NET Core SDKs and Runtimes that will be removed.
remove <VERSION> Remove the specified .NET Core SDKs or Runtimes.
```

### Visual Studio Code (vscode)

[Visual Studio Code - Download](https://code.visualstudio.com/download)

##### CLI (code)

[Dotnet - CLI (code)](https://learn.microsoft.com/en-us/dotnet/core/additional-tools/uninstall-tool?tabs=macos)

###### PATH

```
cat << EOF >> ~/.zprofile
# Add Visual Studio Code (code)
export PATH="\${PATH}:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF
```

## Helpful

```
code ~/.zshrc
dotnet-install --channel LTS
dotnet-install --runtime dotnet --version 6.0.0
dotnet-install --channel 6.0 --runtime aspnetcore
dotnet-core-uninstall list
dotnet-core-uninstall remove --sdk 6.0.201
dotnet-core-uninstall remove --runtime 6.0.3
```
25 changes: 25 additions & 0 deletions home/.git-template/hooks/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Git Hooks

[Git - Hooks](https://git-scm.com/docs/githooks)

### pre-commit

[pre-commit - Installation](https://pre-commit.com/#installation)
[pre-commit - Hooks](https://pre-commit.com/hooks.html)

##### Install with Homebrew

```
brew install pre-commit
```

```
pre-commit --version
```

## Helpful (CLI)

```
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit
```
37 changes: 20 additions & 17 deletions home/.sh/brew-helper.zsh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

# Ask for the administrator password upfront.
sudo -v
# export HOMEBREW_PREFIX=/usr/local
# export HOMEBREW_CELLAR=/usr/local/Cellar
# export HOMEBREW_REPOSITORY=/usr/local/Homebrew
# HOMEBREW_PREFIX=/usr/local
# HOMEBREW_CELLAR=/usr/local/Cellar
# HOMEBREW_REPOSITORY=/usr/local/Homebrew
# export HOMEBREW_PREFIX HOMEBREW_CELLAR HOMEBREW_REPOSITORY

# Info
# sudo xcode-select --install
Expand All @@ -19,20 +20,22 @@ sudo -v
## Permission issues
# sudo chown -R $(whoami) $(brew --prefix)/*

## Update & upgrade
brew update & upgrade
# Check for brew (Homebrew)
if command -v brew 1>/dev/null 2>&1; then
## Update & upgrade
brew update && brew upgrade

# Install brew packages
brew install coreutils # Install GNU core utilities (those that come with OS X are outdated)
brew install wget --with-iri # Install standard `vim` with IRI support
brew install vim --override-system-vi # Install vim with vi override
brew install findutils # Install GNU `find`, `locate`, `updatedb`, and `xargs`, `g`-prefixed.
brew install pre-commit # Install pre-commit package manager (https://pre-commit.com/#install)
brew install gnupg # Install gpg (GnuPG)
#brew install grep tmux tree # Install others
# Install brew packages
brew install -sq coreutils # Install GNU core utilities (those that come with OS X are outdated)
brew install -sq wget # Install standard `vim` with IRI support
brew install -sq findutils # Install GNU `find`, `locate`, `updatedb`, and `xargs`, `g`-prefixed.
brew install -sq pre-commit # Install pre-commit package manager (https://pre-commit.com/#install)
brew install -sq gnupg # Install gpg (GnuPG)
brew install -sq tree # Install tree

## Create symlinks
#sudo ln -s /usr/local/bin/gsha256sum /usr/local/bin/sha256sum
## Create symlinks
#sudo ln -s /usr/local/bin/gsha256sum /usr/local/bin/sha256sum

## Remove outdated versions
brew cleanup
## Remove outdated versions
brew cleanup
fi
1 change: 0 additions & 1 deletion home/.sh/colors-helper.zsh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# colors (default + 8 escapes).
#
T='gYw' # The test text to display

echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";

Expand Down
30 changes: 30 additions & 0 deletions home/.sh/dotnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/zsh
# shellcheck disable=all
# Install dotnet command-line tools (https://learn.microsoft.com/en-us/dotnet/core/install/)
[ -d "${HOME}/.dotnet" ] || mkdir -p "${HOME}/.dotnet"

# dotnet-install
# https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script#recommended-version
typeset -r vcli_lab_ifile='https://dot.net/v1/dotnet-install.sh'
(cd "${HOME}/.dotnet" && curl -sL -o 'dotnet-install' "${vcli_lab_ifile}")
(cd "${HOME}/.dotnet" && chmod 0750 'dotnet-install')

# dotnet-uninstall
# https://github.com/dotnet/cli-lab/releases/latest
typeset -r vcli_lab='1.5.255402'
typeset -r vcli_lab_ufile='dotnet-core-uninstall.tar.gz'
(cd "${HOME}/.dotnet" && curl -sL -o "${vcli_lab_ufile}" "https://github.com/dotnet/cli-lab/releases/download/${vcli_lab}/${vcli_lab_ufile}")
(cd "${HOME}/.dotnet" && tar -zxf "${vcli_lab_ufile}" && rm "${vcli_lab_ufile}")

# Adding Dotnet to .zshrc
typeset -r _ZSHRC="${HOME}/.zshrc"
if ! grep -i "\${HOME}/.dotnet" "${_ZSHRC}" 1>/dev/null 2>&1; then
(cat << EOF >> "${_ZSHRC}"
# Dotnet
DOTNET_ROOT="${HOME}/.dotnet"
DOTNET_INSTALL_DIR="${HOME}/.dotnet"
PATH="\${PATH}:${HOME}/.dotnet"
export DOTNET_ROOT DOTNET_INSTALL_DIR PATH
EOF
)
fi
41 changes: 41 additions & 0 deletions home/.sh/golang.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/zsh
# shellcheck disable=all

# Go
# https://go.dev/doc/install
# https://pkg.go.dev/cmd/go#section-directories

# Go Environment (go env)
# https://github.com/golang/go/wiki/SettingGOPATH#zsh
# GOARCH="amd64"
# GOBIN=""
# GOFLAGS=""
# GOOS="darwin"
# GOPATH=""
# GOPROXY="https://proxy.golang.org,direct"
typeset -r GOPATH="${HOME}/go"
export GOPATH

# Adding Golang to .zshrc
typeset -r _ZSHRC="${HOME}/.zshrc"
if ! grep -i "\${PATH}:${GOPATH}" "${_ZSHRC}" 1>/dev/null 2>&1; then
(cat << EOF >> "${_ZSHRC}"
# Golang
export PATH="\${PATH}:${GOPATH}"
EOF
)
fi

# f: _chk_go, install golang and print version
_chk_go() {
# Install go via Homebrew (fastest)
if command -v brew 1>/dev/null 2>&1; then
brew install -sq go
fi
}
_chk_go

# Check for golang
if command -v go 1>/dev/null 2>&1; then
[ -d "${GOPATH}" ] || mkdir -p "${GOPATH}/{bin,pkg,src}";
fi
Loading

0 comments on commit bc463cc

Please sign in to comment.