diff --git a/bin/hosts b/bin/hosts deleted file mode 100755 index 5146370..0000000 --- a/bin/hosts +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -# Path to your hosts file -hostsFile="/etc/hosts" - -# Hostname to add/remove. -hostname="$2" - -yell() { echo "$0: $*" >&2; } -die() { yell "$*"; exit 111; } -try() { "$@" || die "cannot $*"; } - -remove() { - if grep -qP "[[:space:]]$hostname" "$hostsFile"; then - echo "$hostname found in $hostsFile. Removing now..." - try sudo sed -ie "/[[:space:]]$hostname/d" "$hostsFile" - else - yell "$hostname was not found in $hostsFile" - fi -} - -add() { - if grep -qP "[[:space:]]$hostname" "$hostsFile"; then - yell "$hostname already exists: $(grep "$hostname" $hostsFile)" - else - echo "Adding $hostname to $hostsFile..." - try printf "%s\t%s\n" "127.0.0.1" "$hostname" | sudo tee -a "$hostsFile" > /dev/null - - if grep -q "$hostname" "$hostsFile"; then - echo "$hostname was added succesfully:" - grep "$hostname" "$hostsFile" - else - die "Failed to add $hostname" - fi - fi -} - -"$@" diff --git a/bin/notify b/bin/notify deleted file mode 100755 index 6dd80e9..0000000 --- a/bin/notify +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env php -= 5.1 is required. + autoload -Uz is-at-least && is-at-least 5.1 || return + + # Prompt colors. + local grey='242' + local red='1' + local yellow='3' + local blue='4' + local magenta='5' + local cyan='6' + local white='7' + + # Left prompt segments. + typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=( + # =========================[ Line #1 ]========================= + context # user@host + dir # current directory + vcs # git status + command_execution_time # previous command duration + time + # =========================[ Line #2 ]========================= + newline # \n + virtualenv # python virtual environment + prompt_char # prompt symbol + ) + + # Right prompt segments. + typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( + # =========================[ Line #1 ]========================= + # command_execution_time # previous command duration + # virtualenv # python virtual environment + # context # user@host + #time # current time + # =========================[ Line #2 ]========================= + newline # \n + ) + + # Basic style options that define the overall prompt look. + typeset -g POWERLEVEL9K_BACKGROUND= # transparent background + typeset -g POWERLEVEL9K_{LEFT,RIGHT}_{LEFT,RIGHT}_WHITESPACE= # no surrounding whitespace + typeset -g POWERLEVEL9K_{LEFT,RIGHT}_SUBSEGMENT_SEPARATOR=' ' # separate segments with a space + typeset -g POWERLEVEL9K_{LEFT,RIGHT}_SEGMENT_SEPARATOR= # no end-of-line symbol + typeset -g POWERLEVEL9K_VISUAL_IDENTIFIER_EXPANSION= # no segment icons + + # Add an empty line before each prompt except the first. This doesn't emulate the bug + # in Pure that makes prompt drift down whenever you use the Alt-C binding from fzf or similar. + typeset -g POWERLEVEL9K_PROMPT_ADD_NEWLINE=false + + # Magenta prompt symbol if the last command succeeded. + typeset -g POWERLEVEL9K_PROMPT_CHAR_OK_{VIINS,VICMD,VIVIS}_FOREGROUND=$magenta + # Red prompt symbol if the last command failed. + typeset -g POWERLEVEL9K_PROMPT_CHAR_ERROR_{VIINS,VICMD,VIVIS}_FOREGROUND=$red + # Default prompt symbol. + typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIINS_CONTENT_EXPANSION='❯' + # Prompt symbol in command vi mode. + typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VICMD_CONTENT_EXPANSION='❮' + # Prompt symbol in visual vi mode is the same as in command mode. + typeset -g POWERLEVEL9K_PROMPT_CHAR_{OK,ERROR}_VIVIS_CONTENT_EXPANSION='❮' + # Prompt symbol in overwrite vi mode is the same as in command mode. + typeset -g POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE=false + + # Grey Python Virtual Environment. + typeset -g POWERLEVEL9K_VIRTUALENV_FOREGROUND=$grey + # Don't show Python version. + typeset -g POWERLEVEL9K_VIRTUALENV_SHOW_PYTHON_VERSION=false + typeset -g POWERLEVEL9K_VIRTUALENV_{LEFT,RIGHT}_DELIMITER= + + # Blue current directory. + typeset -g POWERLEVEL9K_DIR_FOREGROUND=$blue + + # Context format when root: user@host. The first part white, the rest grey. + typeset -g POWERLEVEL9K_CONTEXT_ROOT_TEMPLATE="%F{$white}%n%f%F{$grey}@%m%f" + # Context format when not root: user@host. The whole thing grey. + typeset -g POWERLEVEL9K_CONTEXT_TEMPLATE="%F{$grey}%n@%m%f" + # Don't show context unless root or in SSH. + typeset -g POWERLEVEL9K_CONTEXT_{DEFAULT,SUDO}_CONTENT_EXPANSION= + + # Show previous command duration only if it's >= 5s. + typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_THRESHOLD=5 + # Don't show fractional seconds. Thus, 7s rather than 7.3s. + typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_PRECISION=0 + # Duration format: 1d 2h 3m 4s. + typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FORMAT='d h m s' + # Yellow previous command duration. + typeset -g POWERLEVEL9K_COMMAND_EXECUTION_TIME_FOREGROUND=$yellow + + # Grey Git prompt. This makes stale prompts indistinguishable from up-to-date ones. + typeset -g POWERLEVEL9K_VCS_FOREGROUND=$grey + + # Disable async loading indicator to make directories that aren't Git repositories + # indistinguishable from large Git repositories without known state. + typeset -g POWERLEVEL9K_VCS_LOADING_TEXT= + + # Don't wait for Git status even for a millisecond, so that prompt always updates + # asynchronously when Git state changes. + typeset -g POWERLEVEL9K_VCS_MAX_SYNC_LATENCY_SECONDS=0 + + # Cyan ahead/behind arrows. + typeset -g POWERLEVEL9K_VCS_{INCOMING,OUTGOING}_CHANGESFORMAT_FOREGROUND=$cyan + # Don't show remote branch, current tag or stashes. + typeset -g POWERLEVEL9K_VCS_GIT_HOOKS=(vcs-detect-changes git-untracked git-aheadbehind) + # Don't show the branch icon. + typeset -g POWERLEVEL9K_VCS_BRANCH_ICON= + # When in detached HEAD state, show @commit where branch normally goes. + typeset -g POWERLEVEL9K_VCS_COMMIT_ICON='@' + # Don't show staged, unstaged, untracked indicators. + typeset -g POWERLEVEL9K_VCS_{STAGED,UNSTAGED,UNTRACKED}_ICON= + # Show '*' when there are staged, unstaged or untracked files. + typeset -g POWERLEVEL9K_VCS_DIRTY_ICON='*' + # Show '⇣' if local branch is behind remote. + typeset -g POWERLEVEL9K_VCS_INCOMING_CHANGES_ICON=':⇣' + # Show '⇡' if local branch is ahead of remote. + typeset -g POWERLEVEL9K_VCS_OUTGOING_CHANGES_ICON=':⇡' + # Don't show the number of commits next to the ahead/behind arrows. + typeset -g POWERLEVEL9K_VCS_{COMMITS_AHEAD,COMMITS_BEHIND}_MAX_NUM=1 + # Remove space between '⇣' and '⇡' and all trailing spaces. + typeset -g POWERLEVEL9K_VCS_CONTENT_EXPANSION='${${${P9K_CONTENT/⇣* :⇡/⇣⇡}// }//:/ }' + + # Grey current time. + typeset -g POWERLEVEL9K_TIME_FOREGROUND=$yellow + # Format for the current time: 09:51:02. See `man 3 strftime`. + typeset -g POWERLEVEL9K_TIME_FORMAT='%D{%H:%M:%S}' + # If set to true, time will update when you hit enter. This way prompts for the past + # commands will contain the start times of their commands rather than the end times of + # their preceding commands. + typeset -g POWERLEVEL9K_TIME_UPDATE_ON_COMMAND=false + + # Transient prompt works similarly to the builtin transient_rprompt option. It trims down prompt + # when accepting a command line. Supported values: + # + # - off: Don't change prompt when accepting a command line. + # - always: Trim down prompt when accepting a command line. + # - same-dir: Trim down prompt when accepting a command line unless this is the first command + # typed after changing current working directory. + typeset -g POWERLEVEL9K_TRANSIENT_PROMPT=always + + # Instant prompt mode. + # + # - off: Disable instant prompt. Choose this if you've tried instant prompt and found + # it incompatible with your zsh configuration files. + # - quiet: Enable instant prompt and don't print warnings when detecting console output + # during zsh initialization. Choose this if you've read and understood + # https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt. + # - verbose: Enable instant prompt and print a warning when detecting console output during + # zsh initialization. Choose this if you've never tried instant prompt, haven't + # seen the warning, or if you are unsure what this all means. + typeset -g POWERLEVEL9K_INSTANT_PROMPT=verbose + + # Hot reload allows you to change POWERLEVEL9K options after Powerlevel10k has been initialized. + # For example, you can type POWERLEVEL9K_BACKGROUND=red and see your prompt turn red. Hot reload + # can slow down prompt by 1-2 milliseconds, so it's better to keep it turned off unless you + # really need it. + typeset -g POWERLEVEL9K_DISABLE_HOT_RELOAD=true + + # If p10k is already loaded, reload configuration. + # This works even with POWERLEVEL9K_DISABLE_HOT_RELOAD=true. + (( ! $+functions[p10k] )) || p10k reload +} + +# Tell `p10k configure` which file it should overwrite. +typeset -g POWERLEVEL9K_CONFIG_FILE=${${(%):-%x}:a} + +(( ${#p10k_config_opts} )) && setopt ${p10k_config_opts[@]} +'builtin' 'unset' 'p10k_config_opts' diff --git a/zsh/files/hosts.zsh b/zsh/files/hosts.zsh new file mode 100644 index 0000000..134e608 --- /dev/null +++ b/zsh/files/hosts.zsh @@ -0,0 +1,28 @@ +removehost() { + hostname="$1" + + if grep -qP "[[:space:]]$hostname" /etc/hosts; then + echo "$hostname found in /etc/hosts. Removing now..." + sudo sed -ie "/[[:space:]]$hostname/d" /etc/hosts || echo "cannot remove host from /etc/hosts" >&2 + else + echo "$hostname was not found in /etc/hosts" >&2 + fi +} + +addhost() { + hostname="$1" + + if grep -qP "[[:space:]]$hostname" /etc/hosts; then + echo "$hostname already exists: $(grep "$hostname" /etc/hosts)" >&2 + else + echo "Adding $hostname to /etc/hosts..." + printf "%s\t%s\n" "127.0.0.1" "$hostname" | sudo tee -a /etc/hosts > /dev/null || echo "cannot add host to /etc/hosts" >&2 + + if grep -q "$hostname" /etc/hosts; then + echo "$hostname was added succesfully:" + grep "$hostname" /etc/hosts + else + echo "Failed to add $hostname" >&2 + fi + fi +} diff --git a/zsh/rc.zsh b/zsh/rc.zsh index 1be8ac8..923c6db 100644 --- a/zsh/rc.zsh +++ b/zsh/rc.zsh @@ -1,4 +1,6 @@ -export path=($path $HOME/.config/dotfiles/bin) +# Enable Powerlevel10k instant prompt +[[ -r "$HOME/.cache/p10k-instant-prompt-${(%):-%n}.zsh" ]] && source "$HOME/.cache/p10k-instant-prompt-${(%):-%n}.zsh" + export fpath=($fpath $ZDOTDIR/local/fpath) export FZF_MARKS_FILE=$HOME/.config/fzfmarks export STARSHIP_CONFIG=$ZDOTDIR/starship.toml @@ -28,6 +30,9 @@ zinit ice as"program" from"gh-r" mv"exa* -> exa"; zinit light ogham/exa zinit ice as"program" from"gh-r" mv"pet* -> pet" pick"usr/local/bin/pet"; zinit light knqyf263/pet zinit ice as"program" from"gh-r" mv"ripgrep* -> ripgrep" pick"ripgrep/rg"; zinit load BurntSushi/ripgrep zinit ice as"program" from"gh-r" mv"gopass* -> gopass" pick"gopass/gopass"; zinit load gopasspw/gopass +zinit ice as"program" from"gh-r" mv"jq-* -> jq"; zinit load "stedolan/jq" +zinit ice as"program" pick"emojify"; zinit load "mrowa44/emojify" + # Completions and Autosuggestions zinit ice wait lucid blockf atpull'zinit creinstall -q .'; zinit light zsh-users/zsh-completions @@ -77,13 +82,18 @@ zinit ice wait lucid; zinit light Aloxaf/fzf-tab zinit ice wait lucid; zinit light wfxr/forgit zinit ice wait lucid; zinit light reegnz/jq-zsh-plugin zinit ice wait lucid; zinit light asdf-vm/asdf +zinit ice wait lucid; zinit light b4b4r07/emoji-cli # syntax highlighting zpcompinit zinit ice wait lucid atinit"zpcdreplay -q"; zinit light zsh-users/zsh-syntax-highlighting # Theme -_evalcache starship init zsh +zinit ice depth=1; zinit light romkatv/powerlevel10k +#_evalcache starship init zsh # Local RC [[ -f "$ZDOTDIR/local/rc.zsh" ]] && source "$ZDOTDIR/local/rc.zsh" + +# To customize prompt, run `p10k configure` or edit ~/.config/dotfiles/zsh/.p10k.zsh. +[[ ! -f ~/.config/dotfiles/zsh/.p10k.zsh ]] || source ~/.config/dotfiles/zsh/.p10k.zsh