Skip to content

Commit

Permalink
August 2020 (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Aug 4, 2020
1 parent 2aab079 commit e686ee3
Show file tree
Hide file tree
Showing 36 changed files with 291 additions and 248 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
```bash
# with homebrew or linuxbrew
brew install denisidoro/tools/dotfiles
dot self install

# with git
git clone https://github.com/denisidoro/dotfiles $HOME/dotfiles
$HOME/dotfiles/bin/dot self install
```

## Calling scripts

There's a single entry point for almost all scripts, which is the `dot` command:
```bash
dot <ctx> <cmd> [<args>...] # example: dot rice pipes
```
Expand All @@ -45,22 +48,24 @@ dot <ctx> <cmd> --help # example: dot rice pipes --help
## Shell startup performance

```bash
λ dot shell zsh test-performance
0.08 real 0.03 user 0.03 sys
$ dot shell zsh benchmark
Benchmark #1: /usr/bin/time /bin/zsh -i -c exit
Time (mean ± σ): 35.6 ms ± 3.0 ms [User: 14.0 ms, System: 16.0 ms]
Range (min … max): 32.7 ms … 48.8 ms 67 runs
```

## Overriding configs

Edit the following files accordingly:
```bash
# shell
~/.dotfiles/local/zshrc
vi $DOTFILES/local/zshrc

# git
~/.dotfiles/local/gitconfig
vi $DOTFILES/local/gitconfig
```

## Inspiration
* [Tuurlijk/dotfiles](https://github.com/Tuurlijk/dotfiles): zsh startup snappiness
* [rgomezcasas/dotfiles](https://github.com/rgomezcasas/dotfiles): README, some scripts and fine-tuning
* [Tuurlijk/dotfiles](https://github.com/Tuurlijk/dotfiles): zsh startup snappiness
* [wfxr/forgit](https://github.com/wfxr/forgit): some git scripts
98 changes: 23 additions & 75 deletions bin/dot
Original file line number Diff line number Diff line change
Expand Up @@ -12,82 +12,25 @@ CALLING_DIR="${CALLING_DIR:-"$PWD"}"
##? dot <context>
##? dot <context> <cmd> [<args>...]

list_command_paths() {
find "$DOTFILES/scripts" -maxdepth 2 -executable -type f \
| grep -v core \
| sort
}

list_contexts() {
local paths="$1"
echo "$paths" \
| xargs -I % -d '\n' sh -c 'basename $(dirname %)' \
| uniq
}
_list_command_paths() {
find "${DOTFILES}/scripts" -maxdepth 2 -executable -type f

list_paths_for_context() {
local paths="$1"; local context="$2"
echo "$paths" \
| grep "$context/"
find "${DOTFILES}/local/scripts" -maxdepth 2 -executable -type f \
| sed 's|/local/scripts/|/scripts/|g'
}

list_commands_for_context() {
local paths="$1"; local context="$2"

echo "$paths" \
| grep "$context/" \
| xargs -I % -d '\n' basename "%"
}

exact_match() {
local -r query="$1"
local -r matches="$2"

for m in $matches; do
if [[ "$m" = "$query" ]]; then
return 0
fi
done

exit 1
}

find_match() {
local candidates="$1"
local query="$2"
local matches="$(echo "$candidates" | grep $query)"
local count="$(echo "$matches" | wc -l)"
local exact="$(exact_match "$query" "$matches" || echo "")"
if [[ ! -z "${exact}" ]]; then
RESPONSE="$query"
elif [[ -z "${matches}" ]]; then
echo -e "No matches for $query\n\nPossible values:\n$candidates"
exit 1
elif [ $count -gt 1 ]; then
echo -e "Multiple matches for $query:\n$matches"
exit 2
else
RESPONSE=$(echo "$matches" | head -n 1)
fi
}

find_context() {
local contexts="$1"; local query="$2"
find_match "$contexts" "$query"
CTX=$RESPONSE
list_command_paths() {
_list_command_paths | sort
}

find_command() {
local paths="$1"; local context="$2"; local query="$3"
local commands=$(list_commands_for_context "$paths" "$context")
find_match "$commands" "$query"
CMD=$(basename $RESPONSE)
beautify_command() {
awk -F"/" '{print $(NF-1) " " $NF}'
}

fzf_prompt() {
local paths="$1"
match="$(echo "$paths" \
| xargs -I % sh -c 'echo "$(basename $(dirname %)) $(basename %)"' \
| beautify_command \
| fzf-tmux --height 50% --preview 'dot $(echo {} | cut -d" " -f 1) $(echo {} | cut -d" " -f 2) -h')"
printf "$match "
read args
Expand All @@ -98,6 +41,13 @@ fzf_prompt() {
fi
}

_version() {
cat "${DOTFILES}/rust/Cargo.toml" \
| grep version \
| head -n1 \
| grep -Eo '[0-9\.]+'
}

_alias() {
local -r arg="$1"
case "$arg" in
Expand Down Expand Up @@ -125,28 +75,26 @@ _alias() {
if [[ $# -eq 0 ]]; then
# Shows available contexts
# or prompts for a command if fzf is installed
source "$DOTFILES/scripts/core/main.sh"
source "$DOTFILES/scripts/core/coll.sh"
source "${DOTFILES}/scripts/core/main.sh"
source "${DOTFILES}/scripts/core/coll.sh"

has fzf \
&& fzf_prompt "$(list_command_paths)" \
|| list_contexts "$(list_command_paths)"
|| (list_command_paths | beautify_command)

elif [[ $# -eq 1 ]]; then
# Shows available commands for a given context
source "$DOTFILES/scripts/core/main.sh"
source "${DOTFILES}/scripts/core/main.sh"

context_query="$(_alias $1)"

case $context_query in
-h|--help) doc::help_or_fail "$@" && exit ;;
-v|--version) cat "${DOTFILES}/rust/Cargo.toml" | grep version | head -n1 | grep -Eo '[0-9\.]+' && exit ;;
-v|--version) _version && exit ;;
esac

paths="$(list_command_paths)"
contexts="$(list_contexts "$paths")"
find_context "$contexts" "$context_query"
list_paths_for_context "$paths" "$CTX" | xargs -I % -d '\n' basename "%"
find "${DOTFILES}/scripts/${context_query}/" -maxdepth 2 -executable -type f \
| awk -F"/" '{print $NF}'

else
# Executes a command directly
Expand Down
29 changes: 0 additions & 29 deletions cheats/tmp.cheat

This file was deleted.

2 changes: 1 addition & 1 deletion editors/vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"window.zoomLevel": 1,
"editor.fontSize": 12,
"editor.fontFamily": "Hack Nerd Font",
// "editor.fontFamily": "Hack Nerd Font",
"editor.letterSpacing": 0.2,
"editor.lineHeight": 18,
"editor.renderControlCharacters": true,
Expand Down
20 changes: 17 additions & 3 deletions peripherals/skhd/skhd.rc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,31 @@

:: default : yabai -m config active_window_border_color 0xFF00BFFF
:: grab : yabai -m config active_window_border_color 0xffff1493
:: mark : yabai -m config active_window_border_color 0xffc4fb6d

alt + cmd + ctrl + shift - g ; grab
alt + cmd + ctrl + shift - b ; mark
grab < escape ; default
mark < escape ; default

# =================
# Application
# =================

# launch iTerm
alt + cmd + ctrl + shift - a : open -na /Applications/iTerm.app
alt + cmd + ctrl + shift - return : open -na /Applications/Alacritty.app
# launch terminal
alt + cmd + ctrl + shift - return : open -na /Applications/iTerm.app
alt + cmd + ctrl + shift - a : open -na /Applications/Alacritty.app

# =================
# Bookmarks
# =================

mark < m : $HOME/dotfiles/bin/dot url mark mail
mark < shift - m : $HOME/dotfiles/bin/dot url mark mail work
mark < c : $HOME/dotfiles/bin/dot url mark calendar
mark < shift - c : $HOME/dotfiles/bin/dot url mark calendar work
mark < k : $HOME/dotfiles/bin/dot url mark keep
mark < t : $HOME/dotfiles/bin/dot url mark test

# =================
# Power
Expand Down
2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dotrs"
version = "2020.6.16"
version = "2020.8.6"
authors = ["Denis Isidoro <[email protected]>"]
edition = "2018"
description = "Awesome personal dotfiles"
Expand Down
9 changes: 9 additions & 0 deletions scripts/core/ini.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

ini::get() {
local -r key="$1"

grep -A999 "\[${key}\].*" \
| sed '/^ *$/q' \
| tail -n +2
}
31 changes: 18 additions & 13 deletions scripts/core/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ test::skip() {
return
}

_with_sleep() {
sleep "$1"
shift
"$@"
}

test::run() {
test::filter_check || return 0
echo
Expand All @@ -51,6 +57,18 @@ test::run() {
"$@" && test::success || test::fail
}

test::run_with_retry() {
local -r name="$1"
local -r fn="$2"
shift 2

new_test_fn() {
"$fn" "$@" || _with_sleep 2 "$fn" "$@"
}

test::run "$name" new_test_fn "$@"
}

test::lazy_run() {
test::filter_check || return 0
"$@"
Expand Down Expand Up @@ -107,16 +125,3 @@ test::start() {

test::finish
}

test::with_sleep() {
sleep "$1"
shift
"$@"
}

test::call_with_retry() {
local -r sleep="$1"
local -r fn="$2"
shift 2
"$fn" "$@" || test::with_sleep $sleep "$fn" "$@"
}
29 changes: 11 additions & 18 deletions scripts/package/add
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -euo pipefail

source "${DOTFILES}/scripts/core/main.sh"
source "${DOTFILES}/scripts/core/log.sh"
source "${DOTFILES}/scripts/package/aux/core.sh"

##? Install packages
##?
Expand All @@ -24,27 +25,23 @@ fi
if [ $# -gt 1 ]; then
pkg_failures=0
for package in "$@"; do
dot pkg add "$package" || pkg_failures=$((pkg_failures+1))
dot pkg add $($prevent_recipe && printf %s '--prevent-recipe') "$package" || pkg_failures=$((pkg_failures+1))
done
exit "$pkg_failures"
fi

_is_installed() {
log::success "${package} is already installed"
}

_installing() {
_log::installing() {
log::warning "Attempting to install ${package}..."
}

package="$1"
has "$package" && _is_installed && exit 0
package="$(pkg::alias "$1" "$prevent_recipe")"

dashed_package="$(echo "$package" | tr ' _' '-')"
file="${DOTFILES}/scripts/package/recipes/${dashed_package}.sh"
dot pkg check $($prevent_recipe && printf %s '--prevent-recipe') "$package" && exit 0

file="$(pkg::source_file "$package")"

if $prevent_recipe || ! [ -f "$file" ]; then
_installing
_log::installing
for pkg_mgr in apt apk pkg yum dnf port emerge pacman brew pnpm yarn npm pip; do
dot pkg proxy $pkg_mgr add "$package" && exit 0 || true
done
Expand All @@ -53,14 +50,10 @@ fi

source "$file"

has package::is_installed \
&& package::is_installed &>/dev/null \
&& _is_installed \
&& exit 0

_installing
_log::installing
package::install && log::success "Finished installing ${package}!"

hash -r 2>/dev/null || true
source "${HOME}/.bashrc" 2>/dev/null || true
source "${HOME}/.zshrc" 2>/dev/null || true
source "${HOME}/.zshrc" 2>/dev/null || true
hash -r 2>/dev/null || true
Loading

0 comments on commit e686ee3

Please sign in to comment.