From 4ebbfb0874c59ff0144ffee47c252b5eed167012 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Sat, 26 Jun 2021 15:29:40 -0500 Subject: feat: added bat --- bat.conf | 25 +++++++++++++++ bat/install | 46 +++++++++++++++++++++++++++ bat/shell/keybindings.bash | 65 ++++++++++++++++++++++++++++++++++++++ bat/shell/keybindings.zsh | 77 ++++++++++++++++++++++++++++++++++++++++++++++ bat/uninstall | 9 ++++++ install.conf.yaml | 2 ++ profile | 10 ++++++ sh/aliases.sh | 1 + sh/profile.sh | 8 ----- zshrc | 2 +- 10 files changed, 236 insertions(+), 9 deletions(-) create mode 100644 bat.conf create mode 100755 bat/install create mode 100644 bat/shell/keybindings.bash create mode 100644 bat/shell/keybindings.zsh create mode 100755 bat/uninstall create mode 100644 profile delete mode 100644 sh/profile.sh diff --git a/bat.conf b/bat.conf new file mode 100644 index 0000000..df1d2f2 --- /dev/null +++ b/bat.conf @@ -0,0 +1,25 @@ +# This is `bat`s configuration file. Each line either contains a comment or +# a command-line option that you want to pass to `bat` by default. You can +# run `bat --help` to get a list of all possible configuration options. + +# Specify desired highlighting theme (e.g. "TwoDark"). Run `bat --list-themes` +# for a list of all available themes +--theme="Visual Studio Dark+" + +# Enable this to use italic text on the terminal. This is not supported on all +# terminal emulators (like tmux, by default): +--italic-text=always + +# Uncomment the following line to disable automatic paging: +#--paging=never + +# Uncomment the following line if you are using less version >= 551 and want to +# enable mouse scrolling support in `bat` when running inside tmux. This might +# disable text selection, unless you press shift. +#--pager="less --RAW-CONTROL-CHARS --quit-if-one-screen --mouse" + +# Syntax mappings: map a certain filename pattern to a language. +# Example 1: use the C++ syntax for .ino files +# Example 2: Use ".gitignore"-style highlighting for ".ignore" files +#--map-syntax "*.ino:C++" +#--map-syntax ".ignore:Git Ignore" diff --git a/bat/install b/bat/install new file mode 100755 index 0000000..e3ce8e0 --- /dev/null +++ b/bat/install @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +# general installer for sharkdp's rust based applications + +USAGE="Usage: ${0##*/} " +APPS="Apps: bat, hyperfine, hexyl, fd, vivid, pastel, lscolors, diskus" + +app=$1 + +if [[ -z $app || $app == "help" ]]; then + echo $USAGE >&2 + echo $APPS >&2 + exit 0 +fi + +if [[ "$app" == "list" ]]; then + echo $USAGE >&2 + exit 0 +fi + +if [ ! "$(which $app)" ]; then + current_version=0.0.0 + echo "$app: not installed" +else + current_version=$($app --version | grep -oE "[0-9\.]+") + echo "$app: found $current_version" +fi + +latest_version=$(curl -s "https://github.com/sharkdp/$app/releases/latest" | grep -oE '[0-9]+.[0-9\.]+') + +if [ "$2" ]; then + latest_version=$2 +fi + +if [[ "$current_version" == "$latest_version" ]]; then + echo "$app: up-to-date" +else + echo "$app: new version found $latest_version" + echo "$app: downloading..." + + arch="$(dpkg --print-architecture)" + + curl -fsSLo ${app}_${arch}.deb "https://github.com/sharkdp/$app/releases/download/v$latest_version/${app}_${latest_version}_${arch}.deb" + sudo dpkg -i ${app}_${arch}.deb + rm ${app}_${arch}.deb +fi diff --git a/bat/shell/keybindings.bash b/bat/shell/keybindings.bash new file mode 100644 index 0000000..c227c29 --- /dev/null +++ b/bat/shell/keybindings.bash @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +is_in_git_repo() { + git rev-parse HEAD > /dev/null 2>&1 +} + +fzf-down() { + fzf --height 50% --min-height 20 --border --bind ctrl-/:toggle-preview "$@" +} + +_gf() { + is_in_git_repo || return + git -c color.status=always status --short | + fzf-down -m --ansi --nth 2..,.. \ + --preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1})' | + cut -c4- | sed 's/.* -> //' +} + +_gb() { + is_in_git_repo || return + git branch -a --color=always | grep -v '/HEAD\s' | sort | + fzf-down --ansi --multi --tac --preview-window right:70% \ + --preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1)' | + sed 's/^..//' | cut -d' ' -f1 | + sed 's#^remotes/##' +} + +_gt() { + is_in_git_repo || return + git tag --sort -version:refname | + fzf-down --multi --preview-window right:70% \ + --preview 'git show --color=always {}' +} + +_gh() { + is_in_git_repo || return + git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always | + fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \ + --header 'Press CTRL-S to toggle sort' \ + --preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always' | + grep -o "[a-f0-9]\{7,\}" +} + +_gr() { + is_in_git_repo || return + git remote -v | awk '{print $1 "\t" $2}' | uniq | + fzf-down --tac \ + --preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1}' | + cut -d$'\t' -f1 +} + +_gs() { + is_in_git_repo || return + git stash list | fzf-down --reverse -d: --preview 'git show --color=always {1}' | + cut -d: -f1 +} + +if [[ $- =~ i ]]; then + bind '"\er": redraw-current-line' + bind '"\C-g\C-f": "$(_gf)\e\C-e\er"' + bind '"\C-g\C-b": "$(_gb)\e\C-e\er"' + bind '"\C-g\C-t": "$(_gt)\e\C-e\er"' + bind '"\C-g\C-h": "$(_gh)\e\C-e\er"' + bind '"\C-g\C-r": "$(_gr)\e\C-e\er"' + bind '"\C-g\C-s": "$(_gs)\e\C-e\er"' +fi \ No newline at end of file diff --git a/bat/shell/keybindings.zsh b/bat/shell/keybindings.zsh new file mode 100644 index 0000000..0a6c631 --- /dev/null +++ b/bat/shell/keybindings.zsh @@ -0,0 +1,77 @@ +#!/usr/bin/env zsh + +### Key bindings for git with fzf (https://junegunn.kr/2016/07/fzf-git/) + +is_in_git_repo() { + git rev-parse HEAD > /dev/null 2>&1 +} + +fzf-down() { + fzf --height 50% --min-height 20 --border --bind ctrl-/:toggle-preview "$@" +} + +_gf() { + is_in_git_repo || return + git -c color.status=always status --short | + fzf-down -m --ansi --nth 2..,.. \ + --preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1})' | + cut -c4- | sed 's/.* -> //' +} + +_gb() { + is_in_git_repo || return + git branch -a --color=always | grep -v '/HEAD\s' | sort | + fzf-down --ansi --multi --tac --preview-window right:70% \ + --preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1)' | + sed 's/^..//' | cut -d' ' -f1 | + sed 's#^remotes/##' +} + +_gt() { + is_in_git_repo || return + git tag --sort -version:refname | + fzf-down --multi --preview-window right:70% \ + --preview 'git show --color=always {}' +} + +_gh() { + is_in_git_repo || return + git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always | + fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \ + --header 'Press CTRL-S to toggle sort' \ + --preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always' | + grep -o "[a-f0-9]\{7,\}" +} + +_gr() { + is_in_git_repo || return + git remote -v | awk '{print $1 "\t" $2}' | uniq | + fzf-down --tac \ + --preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1}' | + cut -d$'\t' -f1 +} + +_gs() { + is_in_git_repo || return + git stash list | fzf-down --reverse -d: --preview 'git show --color=always {1}' | + cut -d: -f1 +} + +join-lines() { + local item + while read item; do + echo -n "${(q)item} " + done +} + +bind-git-helper() { + local c + for c in $@; do + eval "fzf-g$c-widget() { local result=\$(_g$c | join-lines); zle reset-prompt; LBUFFER+=\$result }" + eval "zle -N fzf-g$c-widget" + eval "bindkey '^g^$c' fzf-g$c-widget" + done +} + +bind-git-helper f b t r h s +unset -f bind-git-helper \ No newline at end of file diff --git a/bat/uninstall b/bat/uninstall new file mode 100755 index 0000000..c1262cf --- /dev/null +++ b/bat/uninstall @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +app=$1 + +if [ "$(which $app)" ]; then + current_version=$($app --version | grep -oE "[0-9\.]+") + echo "$app: uninstalling $current_version" + sudo apt remove $app +fi \ No newline at end of file diff --git a/install.conf.yaml b/install.conf.yaml index 073d267..862b07b 100644 --- a/install.conf.yaml +++ b/install.conf.yaml @@ -9,8 +9,10 @@ - shell: - [git submodule update --init --recursive, Installing submodules] - [yes | ./fzf/install --bin, Installing fzf] + - [./bat/install bat, Installing bat] - link: + ~/.profile: ~/.bashrc: ~/.zshrc: ~/.p10k.zsh: diff --git a/profile b/profile new file mode 100644 index 0000000..c9905dc --- /dev/null +++ b/profile @@ -0,0 +1,10 @@ +#!/usr/bin/env bash + +# Exports +export DOTFILES="$(cd $(dirname "$(readlink -fm "$0")"); git rev-parse --show-toplevel)" +export FZF_BASE="${DOTFILES}/fzf" +export BAT_CONFIG_PATH="${DOTFILES}/bat.conf" +export MANPAGER="sh -c 'col -bx | bat -l man -p'" + +# Path +PATH=$PATH:$HOME/.local/bin:$HOME/.dotnet/tools:$HOME/.cargo/bin:$DOTFILES/scripts \ No newline at end of file diff --git a/sh/aliases.sh b/sh/aliases.sh index c3ddd06..b3bad9f 100644 --- a/sh/aliases.sh +++ b/sh/aliases.sh @@ -7,6 +7,7 @@ alias ll='ls -lh' alias lla='ls -lA' alias lsa='ls -lah' alias grep='grep --color' +alias cat=bat alias ipa="ip -s -c -h a" alias untar="tar -zxvf " alias py=python3 diff --git a/sh/profile.sh b/sh/profile.sh deleted file mode 100644 index 2563e03..0000000 --- a/sh/profile.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -# Exports -export DOTFILES="${HOME}/dotfiles" -export FZF_BASE="${HOME}/dotfiles/fzf" - -# Path -PATH=$PATH:$HOME/.local/bin:$HOME/.dotnet/tools:$HOME/.cargo/bin:$DOTFILES/scripts \ No newline at end of file diff --git a/zshrc b/zshrc index a210d19..dd671e2 100644 --- a/zshrc +++ b/zshrc @@ -1,6 +1,6 @@ #!/usr/bin/env zsh -source "${DOTFILES:="${HOME}/dotfiles"}/sh/profile.sh" +source "${DOTFILES:="${HOME}/dotfiles"}/profile" # Directory hashtable hash -d .=${HOME}/dotfiles -- cgit v1.2.3-70-g09d2