From 7d9e4ed4262c912d758487e6b55d52490df7069c Mon Sep 17 00:00:00 2001 From: Shuvalov Anton Date: Tue, 26 Nov 2019 12:09:40 +0700 Subject: [PATCH] Commit bunch of changes - Noticable thing: update iterm/vim/tmux based on dark/light macos ui mode --- .exports | 2 +- .gitignore | 1 + .nvimrc | 14 +++++---- .tmux.conf | 67 ++++++++++++++++++++++++++++--------------- .zsh_background_tasks | 6 ++++ .zshrc | 14 +-------- bin/battery | 27 ++++++++++------- bin/iterm-theme | 26 +++++++++++++++++ nvim/plugins.vim | 17 +++++------ nvim/utils.vim | 18 +++++++----- 10 files changed, 124 insertions(+), 68 deletions(-) create mode 100644 .zsh_background_tasks create mode 100755 bin/iterm-theme diff --git a/.exports b/.exports index 270409b..54c69ac 100644 --- a/.exports +++ b/.exports @@ -1,6 +1,6 @@ export VISUAL=vi export EDITOR="$VISUAL" -# export GITHUB_ACCESS_TOKEN=`cat ~/.config/.gh-token` +export GITHUB_ACCESS_TOKEN=`cat ~/.config/.gh-token` # Setup locales # # If you'll got locale related error by `perl -e exit`, you should generate diff --git a/.gitignore b/.gitignore index badcaca..18a782e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ ._* .gtd .gitconfig +.npmrc .byobu/.ssh-agent lib # .tmuxinator/.*.yml diff --git a/.nvimrc b/.nvimrc index 6aa4a51..8ba3a5a 100644 --- a/.nvimrc +++ b/.nvimrc @@ -3,8 +3,13 @@ exec "so" dotfiles . '/nvim/settings.vim' exec "so" dotfiles . '/nvim/plugins.vim' exec "so" dotfiles . '/nvim/utils.vim' +" Update colorscheme based on dark/light interface style +let g:colorschemeDark = 'nord' +let g:colorschemeLight = 'nofrils-light' + +call SetBackgroundMode() +call timer_start(3000, "SetBackgroundMode", {"repeat": -1}) -colorscheme 1989 let mapleader = " " @@ -31,8 +36,10 @@ noremap ce (ale_next_wrap) " JS/TS: noremap jt :TSType -noremap jd :TSGetDiagnostics +noremap jd :ALEGoToDefinition +noremap jr :ALEFindReferences noremap jc :ImportCost +noremap jr :ALEFindReferences " noremap jt :TestNearest " noremap jT :TestVisit @@ -71,6 +78,3 @@ noremap k noremap h noremap l -" automatically clean trailing whitespaces on save -autocmd bufwritepre *.* :call Striptrailingwhitespaces() - diff --git a/.tmux.conf b/.tmux.conf index 2d3a8eb..c60e872 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -4,6 +4,7 @@ bind R source-file ~/.tmux.conf # Ctrl-a as prefix instead of Ctrl-b set -g prefix C-a unbind C-b +bind C-a send-prefix # zsh # set -g default-command /bin/zsh @@ -11,14 +12,13 @@ unbind C-b # https://github.com/jimeh/dotfiles/commit/3838db8 # Linux-safe fix for Mac OS pbcopy, pbpaste, and launchctl -set-option -g default-command "safe-reattach-to-user-namespace -l $SHELL" +# set-option -g default-command "safe-reattach-to-user-namespace -l $SHELL" # set -g default-shell $SHELL # set -g default-command "reattach-to-user-namespace -l ${SHELL}" # have `C-a C-a` send C-a keypress to the current window -bind C-a send-prefix # smart pane switching with awareness of vim splits bind -n S-Up run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U" @@ -43,11 +43,6 @@ bind c new-window -c '#{pane_current_path}' # enable for iTerm (Terminal.app doesn't have mouse support) # set -g mouse-resize-pane on set -g mouse on -set -g history-limit 10000 - -# Faster escape sequences (default is 500ms). -# This helps when exiting insert mode in Vim: http://superuser.com/a/252717/65504 -set -s escape-time 50 # start numbering windows from 1 instead of zero set -g base-index 1 @@ -58,39 +53,65 @@ set-window-option -g pane-base-index 1 # switch to a tmuxinator project bind T command-prompt -p session: "run-shell 'tmuxinator %1'" -# syntax highlighting in Vim -set -g default-terminal "screen-256color" - # disable programs changing window names via terminal escape sequence set-window-option -g allow-rename off -# Panes -set -g main-pane-height 56 - -# status bar -# set -g status-utf8 on -set -g status-fg cyan -set -g status-bg white +set -g main-pane-height 60 -# current session -set -g status-left ' #S#[fg=black]@#H' +set -g status-fg magenta +set -g status-bg black +set -g status-left ' ﮙ #[fg=magenta]#H' set -g status-left-length 30 +set -g status-right-length 100 # window list set -g window-status-format " #[fg=black] #I.#W" -set -g window-status-current-format " #[fg=black,bg=cyan] #I.#W " +set -g window-status-current-format " #[fg=black,bg=magenta] #I.#W " set -g window-status-separator "" # battery and pomo status -set -g status-right ' #(battery) ' -set -g status-interval 15 +set -g status-right "\ + CS:#{continuum_status} |\ + #{online_status} |\ +  #{cpu_percentage}% |\ +  #(top -l1 | awk '/PhysMem/ {print $2}') |\ +  #(df / | tail -n1 | awk '{print $5}') |\ + #{battery_icon} #{battery_percentage} |\ + #(date '+%H:%M') \ +" +set -g status-interval 10 # List of plugins set -g @plugin 'tmux-plugins/tpm' + set -g @plugin 'tmux-plugins/tmux-sensible' -set -g @plugin 'arcticicestudio/nord-tmux' +set -g @plugin 'tmux-plugins/tmux-resurrect' +set -g @plugin 'tmux-plugins/tmux-continuum' + set -g @continuum-boot 'on' + set -g @continuum-boot-options 'iterm,fullscreen' + set -g @continuum-restore 'on' + +set -g @plugin 'tmux-plugins/tmux-battery' + set -g @batt_icon_charge_tier8 '' + set -g @batt_icon_charge_tier7 '' + set -g @batt_icon_charge_tier6 '' + set -g @batt_icon_charge_tier5 '' + set -g @batt_icon_charge_tier4 '' + set -g @batt_icon_charge_tier3 '' + set -g @batt_icon_charge_tier2 '' + set -g @batt_icon_charge_tier1 '' + set -g @batt_icon_status_charged ' ' + set -g @batt_icon_status_charging '' + set -g @batt_icon_status_discharging ' ' + +set -g @plugin 'tmux-plugins/tmux-online-status' + set -g @online_icon "" + set -g @offline_icon "" + +set -g @plugin 'tmux-plugins/tmux-cpu' + # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) run '~/.tmux/plugins/tpm/tpm' diff --git a/.zsh_background_tasks b/.zsh_background_tasks new file mode 100644 index 0000000..326e070 --- /dev/null +++ b/.zsh_background_tasks @@ -0,0 +1,6 @@ + +if [[ ! $(pgrep -f $DOTFILES/bin/iterm-theme) ]]; then + nohup $DOTFILES/bin/iterm-theme > /dev/null 2>&1 & +fi + + diff --git a/.zshrc b/.zshrc index 6d19fa5..ebf0194 100644 --- a/.zshrc +++ b/.zshrc @@ -21,24 +21,12 @@ source $DOTFILES/.exports source $ZSH/oh-my-zsh.sh source $DOTFILES/.aliases source $DOTFILES/lib/emo/prompt.zsh - - -preexec_functions=() -function expand_aliases { - input_command=$1 - expanded_command=$2 - if [ $input_command != $expanded_command ]; then - print -nP $PROMPT - echo $expanded_command - fi -} +source $DOTFILES/.zsh_background_tasks if type brew &>/dev/null; then FPATH=$(brew --prefix)/share/zsh/site-functions:$FPATH fi -preexec_functions+=expand_aliases - type rbenv > /dev/null && eval "$(rbenv init -)" type mux > /dev/null && test -z $TMUX && mux dotfiles diff --git a/bin/battery b/bin/battery index 9379b4b..4904560 100755 --- a/bin/battery +++ b/bin/battery @@ -10,16 +10,21 @@ else current_charge=$(echo $battery_info | grep -o '"CurrentCapacity" = [0-9]\+' | awk '{print $3}') total_charge=$(echo $battery_info | grep -o '"MaxCapacity" = [0-9]\+' | awk '{print $3}') fi +echo $current_charge +echo $total_charge -charged_slots=$(echo "(($current_charge/$total_charge)*10)+1" | bc -l | cut -d '.' -f 1) -if [[ $charged_slots -gt 10 ]]; then - charged_slots=10 -fi - -echo -n '#[fg=red]' -for i in `seq 1 $charged_slots`; do echo -n "$HEART"; done +charged_perc=$(echo "(($current_charge/$total_charge)*100)" | bc -l | cut -d '.' -f 1) +echo "$charged_perc%"; -if [[ $charged_slots -lt 10 ]]; then - echo -n '#[fg=blue]' - for i in `seq 1 $(echo "10-$charged_slots" | bc)`; do echo -n "$HEART"; done -fi +# charged_slots=$(echo "(($current_charge/$total_charge)*10)+1" | bc -l | cut -d '.' -f 1) +# if [[ $charged_slots -gt 10 ]]; then +# charged_slots=10 +# fi +# +# echo -n '#[fg=red]' +# for i in `seq 1 $charged_slots`; do echo -n "$HEART"; done +# +# if [[ $charged_slots -lt 10 ]]; then +# echo -n '#[fg=blue]' +# for i in `seq 1 $(echo "10-$charged_slots" | bc)`; do echo -n "$HEART"; done +# fi diff --git a/bin/iterm-theme b/bin/iterm-theme new file mode 100755 index 0000000..c3dccbf --- /dev/null +++ b/bin/iterm-theme @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +import asyncio +import iterm2 + +async def main(connection): + async with iterm2.VariableMonitor(connection, iterm2.VariableScopes.APP, "effectiveTheme", None) as mon: + while True: + # Block until theme changes + theme = await mon.async_get() + + # Themes have space-delimited attributes, one of which will be light or dark. + parts = theme.split(" ") + if "dark" in parts: + preset = await iterm2.ColorPreset.async_get(connection, "Nord (2)") + else: + preset = await iterm2.ColorPreset.async_get(connection, "OneHalfLight") + + # Update the list of all profiles and iterate over them. + profiles=await iterm2.PartialProfile.async_query(connection) + for partial in profiles: + # Fetch the full profile and then set the color preset in it. + profile = await partial.async_get_full_profile() + await profile.async_set_color_preset(preset) + +iterm2.run_forever(main) diff --git a/nvim/plugins.vim b/nvim/plugins.vim index 56e9fd6..35d1b9c 100644 --- a/nvim/plugins.vim +++ b/nvim/plugins.vim @@ -96,13 +96,13 @@ Plug 'editorconfig/editorconfig-vim' " let g:syntastic_auto_loc_list = 1 " let g:syntastic_check_on_open = 1 " let g:syntastic_check_on_wq = 0 -Plug 'A/vim-import-cost', { 'do': 'npm install' } - augroup import_cost_auto_run - autocmd! - autocmd InsertLeave *.js,*.jsx,*.ts,*.tsx ImportCost - autocmd BufEnter *.js,*.jsx,*.ts,*.tsx ImportCost - autocmd CursorHold *.js,*.jsx,*.ts,*.tsx ImportCost - augroup END +" Plug 'A/vim-import-cost', { 'do': 'npm install' } +" augroup import_cost_auto_run +" autocmd! +" autocmd InsertLeave *.js,*.jsx,*.ts,*.tsx ImportCost +" autocmd BufEnter *.js,*.jsx,*.ts,*.tsx ImportCost +" autocmd CursorHold *.js,*.jsx,*.ts,*.tsx ImportCost +" augroup END Plug 'tyru/open-browser.vim' Plug 'pocari/vim-denite-kind-open-browser' Plug 'pocari/vim-denite-gists' @@ -126,12 +126,13 @@ Plug 'alvan/vim-closetag' \ } Plug 'dense-analysis/ale' let g:airline#extensions#ale#enabled = 1 - let g:ale_open_list = 1 + let g:ale_open_list = 0 let g:ale_list_window_size = 5 let g:ale_fixers = { \ '*': ['remove_trailing_lines', 'trim_whitespace'], \ 'javascript': ['eslint'], \ 'typescript': ['tslint'], \} +Plug 'csscomb/vim-csscomb', {'do': 'npm install -g csscomb'} call plug#end() diff --git a/nvim/utils.vim b/nvim/utils.vim index 05c4a47..b5e0e4f 100644 --- a/nvim/utils.vim +++ b/nvim/utils.vim @@ -4,11 +4,15 @@ autocmd BufReadPost * \ exe "normal! g`\"" | \ endif -" Strip whitespaces -fun! Striptrailingwhitespaces() - let l = line(".") - let c = col(".") - %s/\s\+$//e - call cursor(l, c) -endfun + +" let g:colorschemeDark = '1989' +" let g:colorschemeLight = 'nofrils-light' +function! SetBackgroundMode(...) + " dark mode enabled? + if system("defaults read -g AppleInterfaceStyle") =~ '^Dark' + execute "colorscheme ". g:colorschemeDark + else + execute "colorscheme ". g:colorschemeLight + endif +endfunction