diff --git a/README.md b/README.md deleted file mode 100644 index 7f08c298f..000000000 --- a/README.md +++ /dev/null @@ -1,95 +0,0 @@ -# Awesome Dotfiles - -Simple, but extensive customization of ZSH, TMUX, and Vim. - -[![VideoWalkthrough](https://img.youtube.com/vi/UgDz_9i2nwc/0.jpg)](https://www.youtube.com/watch?v=UgDz_9i2nwc) - -## Setup Options - -There's 3 ways in which you can use this, depending on how much you think you'll be customizing. - -One of the key features is that this implementation stays in sync across all your machines. So depending on how much you'd like to customize your configuration, you have a few options: - -* Little Customization: Just clone this repo and jump to [Installation](#installation). -* Mild Customization: [Fork]() this repo, and clone your own fork. Keep an eye on this repo for bugfixes and other improvements that you'd like to incorporate into your fork. Then jump to [Installation](#installation). -* Most Customization: Building your own dotfiles from scratch! Read through these docs, watch the video above, star this repo, and create your own dotfiles! You can add this repository as a [git module](https://git-scm.com/book/en/v2/Git-Tools-Submodules) and source the parts you like. - -If you're unsure, just read the docs, watch the video, clone this repository, and jump to [Installation](#installation). - -## Installation - -Once the repo is cloned, execute the deploy script: -``` -./deploy -``` - -This script guides you through the following: - -1. Checks to see if you have zsh, tmux, and vim installed. -2. Installs them using your default package manager if you don't have some of them installed. -3. Checks to see if your default shell is zsh. -4. Sets zsh to your default shell. -5. Backs up your old configuration files. - -Pretty convenient for configuring new servers. - -# Summary of Changes - -## Basic runtime opperations - -All default dotfiles (`.zshrc`, `.vimrc`, etc) source something within the dotfiles repository. This helps separate changes that are synced across all your machines with system specific changes. - -Upon launching a new shell, the first thing that's evaulated is `zshrc_manager.sh`. This script first launches tmux. Then once zsh logs in, within tmux, it updates the dotfiles repository, and sources the changes. - -## [Zsh](https://en.wikipedia.org/wiki/Z_shell) - -* `cd` has been reassigned to `cd` and `ls`. Every time you navigate to a new directory, it will display the content of that directory. -* `v` has been aliased too: `vim -p`. This let's you open multiple files in vim as tabs. - -### Prompt - -The prompt takes on the form: - -``` -[plugin, plugin, ...]: -``` - -Each plugin is sensitive to where you are and what you're doing, they reveal themselves when it's contextually relevant. Plugins include: - -* `PWD plugin`: always present, tells you where you are. Always the first plugin. -* `Status code plugin`: appears anytime a program returns with a non-zero status code. Tells you what status code the program completed with. -* `Git plugin`: appears when you're in a git repository. Tells you what branch you're on, and how many files have been changed since the last commit. -* `Sudo plugin`: tells you when you can sudo without a password. Or when you're logged in as root. -* `Time plugin`: appears when a program took more than 1s to execute. Tells you how long it took to execute. -* `PID plugin`: appears when you background a task. Tells you what the PID of the task is. - -### Keybindings -| Key Stroke | What It Does | -|------------|--------------| -| Ctrl-H | Runs ``cd ~/`` | -| Ctrl-K | Runs ``cd ..`` | -| Ctrl-G | Runs ``git add -A; git commit -v && git push`` | -| Ctrl-V | Runs ``fc``. Takes last command and puts it in a vim buffer. | -| Ctrl-S | Adds ``sudo`` to the beginning of the buffer. | -| Ctrl-L | Runs ``ls``. | -| Ctrl-O | Equivalent to hitting ``Enter``. | -| Ctrl-P | Equivalent to pressing ``Up Arrow``. | - -### Plugins - -* [zsh-autosuggestions](https://github.com/zsh-users/zsh-autosuggestions): Searches your history while you type and provides suggestions. -* [zsh-syntax-highlighting](https://github.com/zsh-users/zsh-syntax-highlighting/tree/ad522a091429ba180c930f84b2a023b40de4dbcc): Provides fish style syntax highlighting for zsh. -* [ohmyzsh](https://github.com/robbyrussell/oh-my-zsh/tree/291e96dcd034750fbe7473482508c08833b168e3): Borrowed things like tab completion, fixing ls, tmux's vi-mode plugin. -* [vimode-zsh](https://github.com/robbyrussell/oh-my-zsh/tree/master/plugins/vi-mode) allows you to hit `esc` and navigate the current buffer using vim movement keys. - -## [Vim](https://en.wikipedia.org/wiki/Vim_(text_editor)) - -* Leader key has ben remapped to `,` - -## [Tmux](https://en.wikipedia.org/wiki/Tmux) - -* Ctrl-B has been remapped to the backtick character (`). If you want to type the actual backtick character (`) itself, just hit the key twice. -* `%` has been remapped to `v`. -* Use vim movement keys for moving between panes. -* Copy buffer is coppied to xclip. -* Status bar tells you date, time, user, and hostname. Especially useful with nested ssh sessions. diff --git a/bashrc.sh b/bashrc.sh new file mode 100644 index 000000000..27ac833a2 --- /dev/null +++ b/bashrc.sh @@ -0,0 +1,63 @@ +export VISUAL=vim +export EDITOR="$VISUAL" + +shopt -s checkwinsize + +alias rand_console='tr -cd "[:alnum:]" < /dev/urandom | fold -w`tput cols`' + +# fuzzy search in chrome history +c() { + local cols sep google_history open + cols=$(( COLUMNS / 3 )) + sep='{::}' + + if [ "$(uname)" = "Darwin" ]; then + google_history="$HOME/Library/Application Support/Google/Chrome/Default/History" + open=open + else + google_history="$HOME/.config/google-chrome/Default/History" + open=xdg-open + fi + cp -f "$google_history" /tmp/h + sqlite3 -separator $sep /tmp/h \ + "select substr(title, 1, $cols), url + from urls order by last_visit_time desc" | + awk -F $sep '{printf "%-'$cols's \x1b[36m%s\x1b[m\n", $1, $2}' | + fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs $open > /dev/null 2> /dev/null +} + +man-find() { + f=$(fd . $MANPATH/man${1:-1} -t f -x echo {/.} | fzf) && man $f +} +fman() { + man -k . | fzf --prompt='Man> ' | awk '{print $1}' | xargs -r man +} + +# don't put duplicate lines or lines starting with space in the history. +# See bash(1) for more options +HISTCONTROL=ignoreboth + +# append to the history file, don't overwrite it +shopt -s histappend + +# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) +HISTSIZE=1000 +HISTFILESIZE=2000 + +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize + +# Add an "alert" alias for long running commands. Use like so: +# sleep 10; alert +alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' + +# vim smali syntax +echo au BufRead,BufNewFile *.smali set filetype=smali >> ~/.vim/filetype.vim + && mkdir ~/.vim/syntax && cd $_ && wget http://codetastrophe.com/smali.vim + +alias switch_proxy='sudo systemctl reload tor.service && curl -s -x socks5h://localhost:9050 ifconfig.me && echo' + +# Disable Ctrl+S (Pause) and Ctrl+Q (continue) shortcuts, I use Ctrl+S to save inside Vim +stty -ixon + diff --git a/deploy b/deploy.sh similarity index 66% rename from deploy rename to deploy.sh index 13e48d429..a546866f4 100755 --- a/deploy +++ b/deploy.sh @@ -76,6 +76,11 @@ check_for_software vim echo check_for_software tmux echo +check_for_software git +echo +check_for_software xclip +# TODO apt install vim-gnome cmake gcc libssl-dev libwebsockets-dev pkg-config +echo check_default_shell @@ -97,5 +102,56 @@ printf "source '$HOME/dotfiles/zsh/zshrc_manager.sh'" > ~/.zshrc printf "so $HOME/dotfiles/vim/vimrc.vim" > ~/.vimrc printf "source-file $HOME/dotfiles/tmux/tmux.conf" > ~/.tmux.conf +git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf +~/.fzf/install + +########################################### +# TODO add to .bashrc +c() { + local cols sep google_history open + cols=$(( COLUMNS / 3 )) + sep='{::}' + + if [ "$(uname)" = "Darwin" ]; then + google_history="$HOME/Library/Application Support/Google/Chrome/Default/History" + open=open + else + google_history="$HOME/.config/google-chrome/Default/History" + open=xdg-open + fi + cp -f "$google_history" /tmp/h + sqlite3 -separator $sep /tmp/h \ + "select substr(title, 1, $cols), url + from urls order by last_visit_time desc" | + awk -F $sep '{printf "%-'$cols's \x1b[36m%s\x1b[m\n", $1, $2}' | + fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs $open > /dev/null 2> /dev/null +} + + +man-find() { + f=$(fd . $MANPATH/man${1:-1} -t f -x echo {/.} | fzf) && man $f +} +fman() { + man -k . | fzf --prompt='Man> ' | awk '{print $1}' | xargs -r man +} + +export PS1="\t \w\[$(tput sgr0)\]\$ " + +[ -f ~/.fzf.bash ] && source ~/.fzf.bash + +export VISUAL=vim +export EDITOR="$VISUAL" + +alias ll='ls -alF' + +shopt -s checkwinsize + +alias rand_console='tr -cd "[:alnum:]" < /dev/urandom | fold -w`tput cols`' + +########################################### + + +# TODO download mitmproxy, chrome.. JEB & IDA, apktools, docker.. + echo echo "Please log out and log back in for default shell to be initialized." diff --git a/m/inputrc b/m/inputrc new file mode 100644 index 000000000..b1ac5da58 --- /dev/null +++ b/m/inputrc @@ -0,0 +1,40 @@ +# Make tab autocomplete regardless of filename case. +set completion-ignore-case on + +# List all matches in case multiple possible completions are possible. +set show-all-if-ambiguous on + +# Immediately add a trailing slash when autocompleting symlinks to directories. +set mark-symlinked-directories on + +# Use the text that has already been typed as the prefix for searching through +# commands (i.e. more intelligent Up/Down behavior) +#"\e[B": history-search-forward +#"\e[A": history-search-backward + +# Do not autocomplete hidden files unless the pattern explicitly begins with a dot +set match-hidden-files off + +# Show all autocomplete results at once +set page-completions off + +# If there are more than 200 possible completions for a word, ask to show them all +set completion-query-items 200 + +# Show extra file information when completing, like `ls -F` does +set visible-stats on + +# Be more intelligent when autocompleting by also looking at the text after +# the cursor. For example, when the current line is "cd ~/src/mozil", and +# the cursor is on the "z", pressing Tab will not autocomplete it to "cd +# ~/src/mozillail", but to "cd ~/src/mozilla". (This is supported by the +# Readline used by Bash 4.) +set skip-completed-text on + +# Allow UTF-8 input and output, instead of showing stuff like $'\0123\0456' +set input-meta on +set output-meta on +set convert-meta off + +# Use Alt/Meta + Delete to delete the preceding word +#"\e[3;3~": kill-word diff --git a/m/tmux.conf b/m/tmux.conf new file mode 100644 index 000000000..c680c4d1f --- /dev/null +++ b/m/tmux.conf @@ -0,0 +1,191 @@ +# set-environment -g PATH "/usr/local/bin:/bin:/usr/bin" +# Prefix +unbind C-b +set -g prefix § +bind § send-prefix + +# Speed up escape key to speed up vim. +set -sg escape-time 1 +set -g set-titles on +set -g set-titles-string "#T" +# set -g set-titles-string "#{session_name} - #{host}" +set -g terminal-overrides 'xterm*:smcup@:rmcup@' +set -g history-limit 10000 + +# Start windows and panes at 1, not 0 +set -g base-index 1 +set -g pane-base-index 1 +set -g renumber-windows on + +# New window +unbind '"' +unbind % +bind | split-window -h -c "#{pane_current_path}" +bind - split-window -v -c "#{pane_current_path}" +bind c new-window -c "#{pane_current_path}" +set -g mode-style "fg=black,bg=white" + +# Resize the current pane using Prefix+Shift+[H/J/K/L] +bind -r J resize-pane -D 5 +bind -r K resize-pane -U 5 +bind -r H resize-pane -L 5 +bind -r L resize-pane -R 5 + +# Easy Config Reloads +unbind r +bind r source-file ~/.tmux.conf\; display-message "Tmux config reloaded" + +# Direction +bind h select-pane -L +bind j select-pane -D +bind k select-pane -U +bind l select-pane -R + +set -g default-terminal "screen-256color" +set -g default-terminal "tmux-256color" + +set -g focus-events on + +# Use vi keys. +setw -g mode-keys vi +bind -T copy-mode-vi Escape send cancel + +unbind p +bind p paste-buffer +bind -T copy-mode-vi v send -X begin-selection +bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" +# binding 'Enter' to copy and not leave selection mode +bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy" send -X clear-selection + +# don't rename windows automatically +set-option -g allow-rename off + +# Enable mouse support. +set -g mouse on +set -g focus-events on + +# http://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/ +###################### +### DESIGN CHANGES ### +###################### + +# panes +set -g pane-border-style fg=black +# set -g pane-active-border fg=brightred + +## Status bar design +# status line +# set -g status-utf8 on +set -g status-justify left +set -g status-style bg=default +set -g status-style fg=colour12 +set -g status-interval 2 + +# messaging +set -g message-style fg=black +set -g message-style bg=yellow +set -g message-command-style fg=blue +set -g message-command-style bg=black + +# Use shift + arrow key to move between windows in a session +bind -n S-Left previous-window +bind -n S-Right next-window + +#window mode +setw -g mode-style bg=colour6 +setw -g mode-style fg=colour0 + +# window status +setw -g window-status-format " #F#I:#W#F " +setw -g window-status-current-format " #F#I:#W#F " +setw -g window-status-format "#[fg=magenta]#[bg=black] #I #[bg=cyan]#[fg=colour8] #W " +setw -g window-status-current-format "#[bg=brightmagenta]#[fg=colour8] #I #[fg=colour8]#[bg=colour14] #W " +setw -g window-status-current-style bg=colour0 +setw -g window-status-current-style fg=colour11 +setw -g window-status-current-style dim +setw -g window-status-style bg=green +setw -g window-status-style fg=black +setw -g window-status-style reverse + +# Info on left (I don't have a session display for now) +set -g status-left '' + +# loud or quiet? +set-option -g visual-activity off +set-option -g visual-bell off +set-option -g visual-silence off +set-window-option -g monitor-activity off +set-option -g bell-action none + +set -g default-terminal "screen-256color" + +# The modes { +setw -g clock-mode-colour colour135 +setw -g mode-style bold +setw -g mode-style fg=colour196 +setw -g mode-style bg=colour238 + +# } +# The panes { + +set -g pane-border-style bg=colour235 +set -g pane-border-style fg=colour238 +set -g pane-active-border-style bg=colour236 +set -g pane-active-border-style fg=colour7 + +# } +# The statusbar { + +#set -g status-position bottom +#set -g status-style bg=colour234 +#set -g status-style fg=colour137 +set -g status-style dim +set -g status-left '' +set -g status-right '#(iwgetid -r) #[fg=colour7]%a %-d%b%H:%M #[fg=colour9]#{?#(xset -q | grep LED | cut -c63),בע,En} #[fg=colour11]#(upower -i /org/freedesktop/UPower/devices/DisplayDevice | grep percentage | cut -d" " -f15)' + + +set -g status-right-length 50 +set -g status-left-length 20 + +setw -g window-status-current-style fg=colour81 +setw -g window-status-current-style bg=colour238 +setw -g window-status-current-style bold +setw -g window-status-current-format ' #I#[fg=colour250]:#[fg=colour255]#W#[fg=colour50]#F ' + +setw -g window-status-style fg=colour138 +setw -g window-status-style bg=colour235 +setw -g window-status-style none +setw -g window-status-format ' #I#[fg=colour237]:#[fg=colour250]#W#[fg=colour244]#F ' + +setw -g window-status-bell-style bold +setw -g window-status-bell-style fg=colour255 +setw -g window-status-bell-style bg=colour1 + +# } +# The messages { + +set -g message-style bold +set -g message-style fg=colour232 +set -g message-style bg=colour166 + +# } + +bind T command-prompt -p "Google > " "run \"open -a 'Google Chrome' 'https://translate.google.com/?lang=he&sl=auto&tl=iw&text=%%&op=translate' \"" +# TODO fix for OSX +# prompt for terminal opacity percentage, 100 = not transparent +bind t command-prompt -p "Enter Opacity %" "run \"xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * %% / 100)))\"" +# google search & translate +bind g command-prompt -p "Google > " "run \"chrome '? %%' \"" + + +# List of plugins +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-sensible' +set -g @plugin 'tmux-plugins/tmux-resurrect' +set -g @plugin 'tmux-plugins/tmux-continuum' +set -g @continuum-restore 'on' +# set -g @plugin 'fcsonline/tmux-thumbs' +set -g @plugin 'Morantron/tmux-fingers' +# set -g @plugin 'odedlaz/tmux-onedark-theme' +# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) +run -b '~/.tmux/plugins/tpm/tpm' diff --git a/m/vimrc.vim b/m/vimrc.vim new file mode 100644 index 000000000..ddec24f01 --- /dev/null +++ b/m/vimrc.vim @@ -0,0 +1,303 @@ +" plugins +let need_to_install_plugins = 0 +if empty(glob('~/.vim/autoload/plug.vim')) + silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + let need_to_install_plugins = 1 +endif + +call plug#begin() +Plug 'tpope/vim-sensible' +" Plug 'itchyny/lightline.vim' +Plug 'joshdick/onedark.vim' +Plug 'albertorestifo/github.vim' +Plug 'ap/vim-buftabline' +Plug 'airblade/vim-gitgutter' +Plug 'preservim/nerdtree' +Plug 'jistr/vim-nerdtree-tabs' +Plug 'Xuyuanp/nerdtree-git-plugin' +Plug 'jiangmiao/auto-pairs' +Plug 'dense-analysis/ale' +Plug 'majutsushi/tagbar' +Plug 'vim-scripts/indentpython.vim' +Plug 'lepture/vim-jinja' +Plug 'pangloss/vim-javascript' +"Plug 'alvan/vim-closetag' +Plug 'maxmellon/vim-jsx-pretty' +call plug#end() + +filetype plugin indent on +syntax on + +if need_to_install_plugins == 1 + echo "Installing plugins..." + silent! PlugInstall + echo "Done!" + q +endif + +" change to =2 to show the status bar +set laststatus=0 + +" enable 256 colors +set t_Co=256 +"set t_ut= + +" turn on line numbering +set number +set relativenumber +set dir=/tmp/ +if system('uname -s') == "Darwin\n" + set clipboard=unnamed "OSX +else + set clipboard=unnamedplus "Linux +endif + +" sane text files +set fileformat=unix +set encoding=utf-8 +set fileencoding=utf-8 + +hi Cursor ctermfg=White ctermbg=Yellow cterm=bold guifg=white guibg=yellow gui=bold +hi Search cterm=NONE ctermfg=yellow ctermbg=NONE +set hlsearch +nnoremap :nohl:echo "Search Cleared" +nnoremap :set norelativenumber:set nonumber:echo "Line numbers turned off." +nnoremap :set relativenumber:set number:echo "Line numbers turned on." + +" Save +" Ctrl-S is pause in most OS terminals, add "stty -ixon" to ~/.bashrc to +" disable or Ctrl-Q to continue +nnoremap :w! +vnoremap :w! +inoremap :w! + +" sane editing +set showtabline=0 +set tabstop=2 +set shiftwidth=2 +set softtabstop=2 +set colorcolumn=120 +set expandtab +set scrolloff=5 +set backspace=indent,eol,start +set viminfo='25,\"50,n~/.viminfo +autocmd FileType html setlocal tabstop=2 shiftwidth=2 softtabstop=2 +autocmd FileType css setlocal tabstop=2 shiftwidth=2 softtabstop=2 +autocmd FileType javascript setlocal tabstop=2 shiftwidth=2 softtabstop=2 +set noincsearch + +" hit jk fast to exit mode +inoremap jk + +" auto-pairs +au FileType python let b:AutoPairs = AutoPairsDefine({"f'" : "'", "r'" : "'", "b'" : "'"}) + +" word movement +imap bi +nmap b +imap wi +nmap w + +" indent/unindent with tab/shift-tab +nmap >> +nmap << +imap < >gv +vmap m :call ToggleMouse() +function ToggleMouse() + if g:is_mouse_enabled == 1 + echo "Mouse OFF" + set mouse= + let g:is_mouse_enabled = 0 + else + echo "Mouse ON" + set mouse=a + let g:is_mouse_enabled = 1 + endif +endfunction + +" color scheme +syntax on +" onedark.vim override: Don't set a background color when running in a terminal; +" just use the terminal's background color +" `gui` is the hex color code used in GUI mode/nvim true-color mode +" `cterm` is the color code used in 256-color mode +" `cterm16` is the color code used in 16-color mode +if (has("autocmd") && !has("gui_running")) + augroup colorset + autocmd! + let s:white = { "gui": "#ABB2BF", "cterm": "145", "cterm16" : "7" } + " autocmd ColorScheme * call onedark#set_highlight("Normal", { "fg": s:white }) " `bg` will not be styled since there is no `bg` setting + augroup END +endif +colorscheme onedark + +filetype on +filetype plugin indent on + +" " lightline +" set noshowmode +" let g:lightline = { 'colorscheme': 'onedark' } + +" code folding +set foldmethod=manual +set foldlevel=99 + +" wrap toggle +setlocal nowrap +noremap w :call ToggleWrap() +function ToggleWrap() + if &wrap + echo "Wrap OFF" + setlocal nowrap + set virtualedit=all + silent! nunmap + silent! nunmap + silent! nunmap + silent! nunmap + silent! iunmap + silent! iunmap + silent! iunmap + silent! iunmap + else + echo "Wrap ON" + setlocal wrap linebreak nolist + set virtualedit= + setlocal display+=lastline + noremap gk + noremap gj + noremap g + noremap g + inoremap gk + inoremap gj + inoremap g + inoremap g + endif +endfunction + +" Making sure spacebar doesn't have any mapping beforehand +nnoremap +let mapleader=" " +" move through split windows +nmap :wincmd k +nmap :wincmd j +nmap :wincmd h +nmap :wincmd l + +" move through buffers +nmap [ :bp! +nmap ] :bn! +" close buf +nmap x :bpbd# + +" restore place in file from previous session +autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif + +" file browser +let NERDTreeIgnore = ['\.pyc$', '__pycache__'] +let NERDTreeMinimalUI = 1 +let g:nerdtree_open = 0 +map n :call NERDTreeToggle() +function NERDTreeToggle() + NERDTreeTabsToggle + if g:nerdtree_open == 1 + let g:nerdtree_open = 0 + else + let g:nerdtree_open = 1 + wincmd p + endif +endfunction + +function! StartUp() + if 0 == argc() + NERDTree + end +endfunction +autocmd VimEnter * call StartUp() + +" ale +map (ale_next_wrap) +"map (ale_previous_wrap) + +" tags +" sudo apt-get install autoconf && https://askubuntu.com/a/836521/804628 +map t :TagbarToggle +let g:tagbar_width = max([25, winwidth(0) / 5]) + +" copy, cut and paste +vmap "+y +vmap "+c +vmap c"+p +imap "+pa + +" disable autoindent when pasting text +" source: https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode +let &t_SI .= "\[?2004h" +let &t_EI .= "\[?2004l" + +function! XTermPasteBegin() + set pastetoggle=[201~ + set paste + return "" +endfunction + +inoremap [200~ XTermPasteBegin() + +" Opens man page in split window, "ZQ" to close +fun! ReadMan() + " Assign current word under cursor to a script variable: + let s:man_word = expand('') + " Open a new window: + :exe ":wincmd n" + " Read in the manpage for man_word (col -b is for formatting): + :exe ":r!man " . s:man_word . " | col -b" + " Goto first line... + :exe ":goto" + " and delete it: + :exe ":delete" +endfun +" Map the K key to the ReadMan function: +map K :call ReadMan() + +" Map Ctrl+f to open current word search box +nnoremap :vim // % \| !:copen + +" Set vimdiff colorscheme to github like +if &diff + colorscheme github +endif + +" One of the most annoying things about vim for me was that I frequently typed :W instead of :w. +" This is happens because the colon needs a shift, w doesn't. +" I would add 'q:' but it used for command history https://coderwall.com/p/sqteyg/vim-tip-command-history-buffer +command WQ wq +command Wq wq +command W w +command Q q + + + +""""""""""""""""""""""""""""""""""" +" Share via paste.rs +" Visual select and :Share +" Add .extension to url to format code +" Example: .markdown +""""""""""""""""""""""""""""""""" +function! s:share() range + let n = @n + silent! normal gv"ny + let out = system("echo '" . @n . "' | curl --silent --data-binary @- https://paste.rs") + let @n = n + normal `> + put ='' + put ='Share:' + put =out + " also copy to clipboard? + let @+ = out +endfunction +command! -range Share :call s:share() diff --git a/m/zshrc b/m/zshrc new file mode 100644 index 000000000..97c2a9f06 --- /dev/null +++ b/m/zshrc @@ -0,0 +1,53 @@ +export CLICOLOR=1 + +export VISUAL=vim +export EDITOR="$VISUAL" + +# don't put duplicate lines or lines starting with space in the history. See bash(1) for more options +HISTCONTROL=ignoreboth +# for setting history length see HISTSIZE and HISTFILESIZE in bash(1) +HISTSIZE=1000 +HISTFILESIZE=2000 +setopt inc_append_history # To save every command before it is executed +setopt share_history # setopt inc_append_history + +export PS1="\t \w\[$(tput sgr0)\]\$ " + + +alias ll='ls -alF' +alias l='ls -alF' + + +# fuzzy search in chrome history +c() { + local cols sep google_history open + cols=$(( COLUMNS / 3 )) + sep='{::}' + + if [ "$(uname)" = "Darwin" ]; then + google_history="$HOME/Library/Application Support/Google/Chrome/Default/History" + open=open + else + google_history="$HOME/.config/google-chrome/Default/History" + open=xdg-open + fi + cp -f "$google_history" /tmp/h + sqlite3 -separator $sep /tmp/h \ + "select substr(title, 1, $cols), url + from urls order by last_visit_time desc" | + awk -F $sep '{printf "%-'$cols's \x1b[36m%s\x1b[m\n", $1, $2}' | + fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs $open > /dev/null 2> /dev/null +} + + +man-find() { + f=$(fd . $MANPATH/man${1:-1} -t f -x echo {/.} | fzf) && man $f +} +fman() { + man -k . | fzf --prompt='Man> ' | awk '{print $1}' | xargs -r man +} + +# Disable Ctrl+S (Pause) and Ctrl+Q (continue) shortcuts, I use Ctrl+S to save inside Vim +stty -ixon + + diff --git a/misc/ida/hotkeys.py b/misc/ida/hotkeys.py new file mode 100644 index 000000000..ab73a8c5a --- /dev/null +++ b/misc/ida/hotkeys.py @@ -0,0 +1,15 @@ +import webbrowser +import ida_kernwin as kw + + +def google_highlighted(): + """gets textual representation of currently selected identifier + from any current IDA view, opens a new browser tab and googles for it + cerdit: https://github.com/patois + """ + + r = kw.get_highlight(kw.get_current_viewer()) + if r: + webbrowser.open("https://google.com/search?q=%s" % r[0],new=2) + +kw.add_hotkey("Ctrl-Shift-F", google_highlighted) diff --git a/tmux/tmux-keybindings.conf b/tmux/tmux-keybindings.conf deleted file mode 100644 index 72ff8db38..000000000 --- a/tmux/tmux-keybindings.conf +++ /dev/null @@ -1,30 +0,0 @@ -# Prefix -unbind C-b -set -g prefix ` -bind ` send-prefix - -# New window -unbind '"' -unbind % -bind '"' split-window -c "#{pane_current_path}" -bind v split-window -h -c "#{pane_current_path}" -bind c new-window -c "#{pane_current_path}" - -# Easy Config Reloads -bind r source-file ~/.tmux.conf - -# Direction -bind h select-pane -L -bind j select-pane -D -bind k select-pane -U -bind l select-pane -R - -# Vim selection: -unbind [ -bind Escape copy-mode -unbind p -bind p paste-buffer -bind-key -Tcopy-mode-vi 'v' send -X begin-selection -bind-key -Tcopy-mode-vi 'y' send -X copy-pipe "~/dotfiles/utils/copy" - -setw -g mode-keys vi diff --git a/tmux/tmux.conf b/tmux/tmux.conf index 85ddc1bfb..22a7127da 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -1,11 +1,51 @@ +# Prefix +unbind C-b +set -g prefix ` +bind ` send-prefix + +set -g history-limit 50000 + +# Start windows and panes at 1, not 0 +set -g base-index 1 +set -g pane-base-index 1 +set -g renumber-windows on + +# New window +unbind '"' +unbind % +bind | split-window -h -c "#{pane_current_path}" +bind - split-window -v -c "#{pane_current_path}" +bind c new-window -c "#{pane_current_path}" +set -g mode-style "fg=black,bg=white" + +# Easy Config Reloads +unbind r +bind r source-file ~/.tmux.conf\; display-message "Tmux config reloaded" + +# Direction +bind h select-pane -L +bind j select-pane -D +bind k select-pane -U +bind l select-pane -R + set -g default-terminal "screen-256color" -source-file ~/dotfiles/tmux/tmux-keybindings.conf set -g focus-events on +# Vim selection: +unbind [ +bind Escape copy-mode +unbind p +bind p paste-buffer +bind -n C-l send-keys C-l \; run 'sleep 0.1' \; clear +set -g mode-keys vi +bind-key -T copy-mode-vi 'v' send-keys -X begin-selection +bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'xclip -sel clip -i' +# binding 'Enter' to copy and not leave selection mode +bind-key -T copy-mode-vi Enter send-keys -X copy-pipe 'xclip -sel clip -i' '\;' send -X clear-selection + # don't rename windows automatically set-option -g allow-rename off -# Enable mouse mode (tmux 2.1 and above) set -g mouse on # http://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/ @@ -15,7 +55,7 @@ set -g mouse on # panes set -g pane-border-style fg=black -set -g pane-active-border fg=brightred +# set -g pane-active-border fg=brightred ## Status bar design # status line @@ -31,6 +71,10 @@ set -g message-style bg=yellow set -g message-command-style fg=blue set -g message-command-style bg=black +# Use shift + arrow key to move between windows in a session +bind -n S-Left previous-window +bind -n S-Right next-window + #window mode setw -g mode-style bg=colour6 setw -g mode-style fg=colour0 @@ -71,17 +115,19 @@ setw -g mode-style bg=colour238 set -g pane-border-style bg=colour235 set -g pane-border-style fg=colour238 set -g pane-active-border-style bg=colour236 -set -g pane-active-border-style fg=colour51 +set -g pane-active-border-style fg=colour7 # } # The statusbar { -set -g status-position bottom -set -g status-style bg=colour234 -set -g status-style fg=colour137 +#set -g status-position bottom +#set -g status-style bg=colour234 +#set -g status-style fg=colour137 set -g status-style dim set -g status-left '' -set -g status-right '#[fg=colour233,bg=colour245,bold] %A %-I:%M #[fg=colour255,bg=colour000] #(whoami)@#H' +set -g status-right '#(iwgetid -r) #[fg=colour7]%a %-d%b%H:%M #[fg=colour9]#{?#(xset -q | grep LED | cut -c63),בע,En} #[fg=colour11]#(upower -i /org/freedesktop/UPower/devices/DisplayDevice | grep percentage | cut -d" " -f15)' + + set -g status-right-length 50 set -g status-left-length 20 @@ -107,3 +153,24 @@ set -g message-style fg=colour232 set -g message-style bg=colour166 # } + +# prompt for terminal opacity percentage, 100 = not transparent +bind t command-prompt -p "Enter Opacity %" "run \"xprop -id $(xprop -root _NET_ACTIVE_WINDOW | cut -d ' ' -f 5) -f _NET_WM_WINDOW_OPACITY 32c -set _NET_WM_WINDOW_OPACITY $(printf 0x%x $((0xffffffff * %% / 100)))\"" +# google search & translate +bind g command-prompt -p "Google > " "run \"google-chrome '? %%' \"" +bind T command-prompt -p "Google > " "run \"google-chrome 'https://translate.google.com/?q=%%&lang=he' \"" + + +# List of plugins +# run-shell ~/dotfiles/tmux/tmux-fingers/tmux-fingers.tmux +set -g @plugin 'tmux-plugins/tpm' +set -g @plugin 'tmux-plugins/tmux-sensible' +set -g @plugin 'tmux-plugins/tmux-resurrect' +set -g @plugin 'tmux-plugins/tmux-continuum' +set -g @continuum-restore 'on' +# set -g @plugin 'fcsonline/tmux-thumbs' +set -g @plugin 'Morantron/tmux-fingers' +# set -g @plugin 'odedlaz/tmux-onedark-theme' + +# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) +run -b '~/.tmux/plugins/tpm/tpm' diff --git a/utils/copy b/utils/copy deleted file mode 100755 index dfdf61fa2..000000000 --- a/utils/copy +++ /dev/null @@ -1,14 +0,0 @@ -if [[ $OSTYPE == darwin* ]]; then - pbcopy -elif [[ $OSTYPE == cygwin* ]]; then - cat > /dev/clipboard -else - if (( $+commands[xclip] )); then - xclip -in -selection clipboard - elif (( $+commands[xsel] )); then - xsel --clipboard --input - else - print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2 - return 1 - fi -fi diff --git a/vim/vimrc.vim b/vim/vimrc.vim index 53559b651..d4f0a6273 100644 --- a/vim/vimrc.vim +++ b/vim/vimrc.vim @@ -1,98 +1,299 @@ -" General Vim settings - syntax on - let mapleader="," - set autoindent - set tabstop=4 - set shiftwidth=4 - set dir=/tmp/ - set relativenumber - set number - - autocmd Filetype html setlocal sw=2 expandtab - autocmd Filetype javascript setlocal sw=4 expandtab - - set cursorline - hi Cursor ctermfg=White ctermbg=Yellow cterm=bold guifg=white guibg=yellow gui=bold - - set hlsearch - nnoremap :nohl:echo "Search Cleared" - nnoremap :set norelativenumber:set nonumber:echo "Line numbers turned off." - nnoremap :set relativenumber:set number:echo "Line numbers turned on." - - nnoremap n nzzzv - nnoremap N Nzzzv - - nnoremap H 0 - nnoremap L $ - nnoremap J G - nnoremap K gg - - map % - - set backspace=indent,eol,start - - nnoremap za - nnoremap z zMzvzz - - nnoremap vv 0v$ - - set listchars=tab:\|\ - nnoremap :set list! - set pastetoggle= - set mouse=a - set incsearch - -" Language Specific - " Tabs - so ~/dotfiles/vim/sleuth.vim - - " Typescript - autocmd BufNewFile,BufRead *.ts set syntax=javascript - autocmd BufNewFile,BufRead *.tsx set syntax=javascript - - " Markup - inoremap < I<A>yypa/O - - -" File and Window Management - inoremap w :w - nnoremap w :w - - inoremap q :q - nnoremap q :q - - inoremap x :x - nnoremap x :x - - nnoremap e :Ex - nnoremap t :tabnew:Ex - nnoremap v :vsplit:w:Ex - nnoremap s :split:w:Ex - -" Return to the same line you left off at - augroup line_return - au! - au BufReadPost * - \ if line("'\"") > 0 && line("'\"") <= line("$") | - \ execute 'normal! g`"zvzz' | - \ endif - augroup END - -" Auto load - " Triger `autoread` when files changes on disk - " https://unix.stackexchange.com/questions/149209/refresh-changed-content-of-file-opened-in-vim/383044#383044 - " https://vi.stackexchange.com/questions/13692/prevent-focusgained-autocmd-running-in-command-line-editing-mode - autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | checktime | endif - set autoread - " Notification after file change - " https://vi.stackexchange.com/questions/13091/autocmd-event-for-autoread - autocmd FileChangedShellPost * - \ echohl WarningMsg | echo "File changed on disk. Buffer reloaded." | echohl None - -" Future stuff - "Swap line - "Insert blank below and above - -" Fix for: https://github.com/fatih/vim-go/issues/1509 +" plugins +let need_to_install_plugins = 0 +if empty(glob('~/.vim/autoload/plug.vim')) + silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + let need_to_install_plugins = 1 +endif + +call plug#begin() +Plug 'tpope/vim-sensible' +" Plug 'itchyny/lightline.vim' +Plug 'joshdick/onedark.vim' +Plug 'albertorestifo/github.vim' +Plug 'ap/vim-buftabline' +Plug 'airblade/vim-gitgutter' +Plug 'preservim/nerdtree' +Plug 'jistr/vim-nerdtree-tabs' +Plug 'Xuyuanp/nerdtree-git-plugin' +Plug 'jiangmiao/auto-pairs' +Plug 'dense-analysis/ale' +Plug 'majutsushi/tagbar' +Plug 'vim-scripts/indentpython.vim' +Plug 'lepture/vim-jinja' +Plug 'pangloss/vim-javascript' +"Plug 'alvan/vim-closetag' +Plug 'maxmellon/vim-jsx-pretty' +call plug#end() filetype plugin indent on +syntax on + +if need_to_install_plugins == 1 + echo "Installing plugins..." + silent! PlugInstall + echo "Done!" + q +endif + +" change to =2 to show the status bar +set laststatus=0 + +" enable 256 colors +set t_Co=256 +"set t_ut= + +" turn on line numbering +set number +set relativenumber +set dir=/tmp/ +set clipboard=unnamedplus + +" sane text files +set fileformat=unix +set encoding=utf-8 +set fileencoding=utf-8 + +hi Cursor ctermfg=White ctermbg=Yellow cterm=bold guifg=white guibg=yellow gui=bold +hi Search cterm=NONE ctermfg=yellow ctermbg=NONE +set hlsearch +nnoremap :nohl:echo "Search Cleared" +nnoremap :set norelativenumber:set nonumber:echo "Line numbers turned off." +nnoremap :set relativenumber:set number:echo "Line numbers turned on." + +" Save +" Ctrl-S is pause in most OS terminals, add "stty -ixon" to ~/.bashrc to +" disable or Ctrl-Q to continue +nnoremap :w! +vnoremap :w! +inoremap :w! + +" sane editing +set showtabline=0 +set tabstop=2 +set shiftwidth=2 +set softtabstop=2 +set colorcolumn=120 +set expandtab +set scrolloff=5 +set backspace=indent,eol,start +set viminfo='25,\"50,n~/.viminfo +autocmd FileType html setlocal tabstop=2 shiftwidth=2 softtabstop=2 +autocmd FileType css setlocal tabstop=2 shiftwidth=2 softtabstop=2 +autocmd FileType javascript setlocal tabstop=2 shiftwidth=2 softtabstop=2 +set noincsearch + +" hit jk fast to exit mode +inoremap jk + +" auto-pairs +au FileType python let b:AutoPairs = AutoPairsDefine({"f'" : "'", "r'" : "'", "b'" : "'"}) + +" word movement +imap bi +nmap b +imap wi +nmap w + +" indent/unindent with tab/shift-tab +nmap >> +nmap << +imap < >gv +vmap m :call ToggleMouse() +function ToggleMouse() + if g:is_mouse_enabled == 1 + echo "Mouse OFF" + set mouse= + let g:is_mouse_enabled = 0 + else + echo "Mouse ON" + set mouse=a + let g:is_mouse_enabled = 1 + endif +endfunction + +" color scheme +syntax on +" onedark.vim override: Don't set a background color when running in a terminal; +" just use the terminal's background color +" `gui` is the hex color code used in GUI mode/nvim true-color mode +" `cterm` is the color code used in 256-color mode +" `cterm16` is the color code used in 16-color mode +if (has("autocmd") && !has("gui_running")) + augroup colorset + autocmd! + let s:white = { "gui": "#ABB2BF", "cterm": "145", "cterm16" : "7" } + " autocmd ColorScheme * call onedark#set_highlight("Normal", { "fg": s:white }) " `bg` will not be styled since there is no `bg` setting + augroup END +endif +colorscheme onedark + +filetype on +filetype plugin indent on + +" " lightline +" set noshowmode +" let g:lightline = { 'colorscheme': 'onedark' } + +" code folding +set foldmethod=manual +set foldlevel=99 + +" wrap toggle +setlocal nowrap +noremap w :call ToggleWrap() +function ToggleWrap() + if &wrap + echo "Wrap OFF" + setlocal nowrap + set virtualedit=all + silent! nunmap + silent! nunmap + silent! nunmap + silent! nunmap + silent! iunmap + silent! iunmap + silent! iunmap + silent! iunmap + else + echo "Wrap ON" + setlocal wrap linebreak nolist + set virtualedit= + setlocal display+=lastline + noremap gk + noremap gj + noremap g + noremap g + inoremap gk + inoremap gj + inoremap g + inoremap g + endif +endfunction + +" Making sure spacebar doesn't have any mapping beforehand +nnoremap +let mapleader=" " +" move through split windows +nmap :wincmd k +nmap :wincmd j +nmap :wincmd h +nmap :wincmd l + +" move through buffers +nmap [ :bp! +nmap ] :bn! +" close buf +nmap x :bpbd# + +" restore place in file from previous session +autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif + +" file browser +let NERDTreeIgnore = ['\.pyc$', '__pycache__'] +let NERDTreeMinimalUI = 1 +let g:nerdtree_open = 0 +map n :call NERDTreeToggle() +function NERDTreeToggle() + NERDTreeTabsToggle + if g:nerdtree_open == 1 + let g:nerdtree_open = 0 + else + let g:nerdtree_open = 1 + wincmd p + endif +endfunction + +function! StartUp() + if 0 == argc() + NERDTree + end +endfunction +autocmd VimEnter * call StartUp() + +" ale +map (ale_next_wrap) +map (ale_previous_wrap) + +" tags +" sudo apt-get install autoconf && https://askubuntu.com/a/836521/804628 +map t :TagbarToggle +let g:tagbar_width = max([25, winwidth(0) / 5]) + +" copy, cut and paste +vmap "+y +vmap "+c +vmap c"+p +imap "+pa + +" disable autoindent when pasting text +" source: https://coderwall.com/p/if9mda/automatically-set-paste-mode-in-vim-when-pasting-in-insert-mode +let &t_SI .= "\[?2004h" +let &t_EI .= "\[?2004l" + +function! XTermPasteBegin() + set pastetoggle=[201~ + set paste + return "" +endfunction + +inoremap [200~ XTermPasteBegin() + +" Opens man page in split window, "ZQ" to close +fun! ReadMan() + " Assign current word under cursor to a script variable: + let s:man_word = expand('') + " Open a new window: + :exe ":wincmd n" + " Read in the manpage for man_word (col -b is for formatting): + :exe ":r!man " . s:man_word . " | col -b" + " Goto first line... + :exe ":goto" + " and delete it: + :exe ":delete" +endfun +" Map the K key to the ReadMan function: +map K :call ReadMan() + +" Map Ctrl+f to open current word search box +nnoremap :vim // % \| !:copen + +" Set vimdiff colorscheme to github like +if &diff + colorscheme github +endif + +" One of the most annoying things about vim for me was that I frequently typed :W instead of :w. +" This is happens because the colon needs a shift, w doesn't. +" I would add 'q:' but it used for command history https://coderwall.com/p/sqteyg/vim-tip-command-history-buffer +command WQ wq +command Wq wq +command W w +command Q q + + + +""""""""""""""""""""""""""""""""""" +" Share via paste.rs +" Visual select and :Share +" Add .extension to url to format code +" Example: .markdown +""""""""""""""""""""""""""""""""" +function! s:share() range + let n = @n + silent! normal gv"ny + let out = system("echo '" . @n . "' | curl --silent --data-binary @- https://paste.rs") + let @n = n + normal `> + put ='' + put ='Share:' + put =out + " also copy to clipboard? + let @+ = out +endfunction +command! -range Share :call s:share()