README.md (9721B) - raw
1 ## fzfgit scripts 2 3 This is a fork of [`dotbare`](https://github.com/kazhala/dotbare). The scripts are modified to work with a regular `git` directory. 4 5 ## Installation: 6 7 ### Manual - use as a script 8 9 ```sh 10 git clone https://github.com/lmburns/fzfgit.git 11 cd fzfgit 12 make install 13 ``` 14 15 ### zsh 16 17 #### zinit 18 ```sh 19 zinit light lmburns/fzfgit 20 ``` 21 22 #### oh-my-zsh 23 ```sh 24 git clone https://github.com/lmburns/fzfgit.git ${ZDOTDIR:-$HOME}/.oh-my-zsh/custom/plugins/fzfgit 25 26 # Add to .zshrc 27 plugins=( fzfgit ) 28 ``` 29 30 #### Antigen 31 ```sh 32 antigen bundle lmburns/fzfgit 33 ``` 34 35 #### Manual - use as a `zsh` plugin 36 ```sh 37 git clone https://github.com/lmburns/fzfgit.git ${ZDOTDIR:-$HOME}/.fzfgit 38 39 # Add to .zshrc 40 source "${ZDOTDIR:-$HOME}/.fzfgit" 41 ``` 42 43 ### Dependencies: 44 45 * [`fzf`](https://github.com/junegunn/fzf) 46 * [`bat`](https://github.com/sharkdp/bat) 47 * [`delta`](https://github.com/dandavison/delta) 48 * Optional: [`exa`](https://github.com/ogham/exa) or `tree` 49 50 ```sh 51 # macOS installation - linux distributions should have it in their package manager 52 # if not, check the links above to download from Github 53 brew install fzf bat delta exa 54 ``` 55 56 ## Scripts 57 58 ### `fadd` 59 60 Select files/directories or modified files through fzf and stage the selected files/directories. 61 62 - Default: list all modified files and stage selected files. Support multi selection. 63 - `-h, --help`: show the help message of `fadd` and exit. 64 - `-f, --file`: list all files in current directory and stage selected files. Support multi selection. (Used for staging new files to index). 65 - `-d, --dir`: list all directory under current directory and stage selected directory. Support multi selection. (Used for staging new files to index). 66 67 ### `fcheckout` 68 69 Checkout files/commit/branch interactively through fzf. 70 71 - Default: list all modified files and reset selected files back to HEAD. Support multi selection. (Discard all changes) **Note**: if your file is staged, you will need to unstage first before running fcheckout to make it work. 72 - `-h, --help`: show the help message of `fcheckout` and exit. 73 - `-s, --select`: list all tracked files and select a commit to checkout the selected files. Support multi selection. 74 - `-b, --branch`: list all branch and switch/checkout the selected branch. 75 - `-c, --commit`: list all commits and checkout selected commit. 76 - `-y, --yes`: acknowledge all actions that will be taken and skip confirmation. 77 78 ### `fedit` 79 80 Select files/commits through fzf and edit selected files/commits in `$EDITOR`. Editing commits will perform a interactive rebase. 81 82 - Default: list all tracked files and open `$EDITOR` to edit the selected files. Support multi selection. 83 - `-h, --help`: show the help message of `fedit` and exit. 84 - `-m, --modified`: list all modified files and open `$EDITOR` to edit the selected files. Support multi selection. 85 - `-c, --commit`: list all commits and edit the selected commit through interactive rebase. 86 87 ### `flog` 88 89 Interactive log viewer that will prompt you with a menu after selecting a commit. The action menu contains options including edit, reset, revert and checkout the selected commits. 90 91 - Default: list all commits and then prompt menu to select action to perform. 92 - `-h, --help`: show the help message of `flog` and exit. 93 - `-r, --revert`: revert the selected commit and skip action menu. 94 - `-R, --reset`: reset HEAD back to the selected commit and skip action menu. 95 - `-e, --edit`: edit selected commit through interactive rebase and skip action menu. 96 - `-c, --checkout`: checkout selected commit and skip action menu. 97 - `-y, --yes`: acknowledge all actions that will be taken and skip confirmation. 98 99 ### `freset` 100 101 Select staged files or commits through fzf and then reset(unstage) staged files or reset HEAD back to certain commits. Also supports reset HEAD back to certain commits using either `--soft`, `--hard`, `--mixed` flags. More information on differences between flags [here](https://git-scm.com/docs/git-reset#Documentation/git-reset.txt-emgitresetemltmodegtltcommitgt). 102 103 - Default: list all staged files and unstage the selected files. Support multi selection. 104 - `-h, --help`: show the help message of `freset` and exit. 105 - `-c, --commit`: list all commits and then reset HEAD back to the selected commits. (Default: --mixed, put all changes into modified state). 106 - `-S, --soft`: use --soft flag instead of --mixed flag, reset HEAD to certain commit without modifying working tree. 107 - `-H, --hard`: use --hard flag instead of --mixed flag, reset HEAD to certain commit discard all changes from the working tree. 108 - `-y, --yes`: acknowledge all actions that will be taken and skip confirmation. 109 110 ### `fstash` 111 112 View and manage stash interactively. 113 114 - Default: list all stashes and apply the selected stash. (Default: `apply`). 115 - `-h, --help`: show the help message of `fstash` and exit. 116 - `-s, --select`: list modified files and stash the selected files. Support multi selection. 117 - `-d, --delete`: list all stashes and delete selected stash. Support multi selection. 118 - `-p, --pop`: use `pop` instead of `apply`. (`pop` would remove the stash while `apply` preserve the stash). 119 120 121 ### `fstat` 122 123 Display interactive git status menu. Toggle file stage/unstage status interactively. 124 125 - `-h, --help`: show the help message of `fstat` and exit. 126 127 ### `funtrack` 128 129 Stop tracking the selected git files. It could also be used to temporarily stop tracking changes for files and then later on resume tracking changes. 130 131 **Note**: This command has severe limitations. 132 133 By default, selected files are permanently untracked from git. Selected files will be remove from index while keeping the file in your current system. However, when your other machines pull down the changes, the untracked files will be deleted by git. This is a limitation with git. 134 135 `funtrack` does come with capabilities to temporarily untrack files, which will not remove the untracked files from other system. However, this is NOT recommended way to untrack files, explained [here](https://www.git-scm.com/docs/git-update-index#_notes). 136 137 - Default: list all tracked files and permanently untrack the selected files. Support multi selection. 138 - `-h, --help`: show the help message of `funtrack` and exit. 139 - `-t, --temp`: list all tracked files and temporarily untrack changes of the selected files. Support multi selection. 140 - `-r, --resume`: list all tracked files and resume tracking changes of the selected files. 141 - `-y, --yes`: acknowledge all actions that will be taken and skip confirmation. 142 143 ### `fzgrep` 144 145 Grep words within tracked files and select to edit them through fzf. The words are listed as lines in fzf and is separated by columns. First column is the file name, second column is the line number and the third column and beyond are the content of the lines. 146 147 - Default: start searching from 3rd column (excluding the file name and line number during search). 148 - `-h, --help`: show the help message of `fstat` and exit. 149 - `-c COL, --col COL`: specify the column number to start searching (e.g. `fgrep --col 2`). 150 - `-f, --full`: include all column during search, as if using `--col 1`. 151 152 ## Helper scripts 153 154 ### `fgit_helper.sh` 155 156 Provides variables and functions used by some of the scripts mentioned above. 157 158 ### `preview.sh` 159 160 Fzf preview window coloring. 161 162 ## Environment variables 163 164 ### `FZFGIT_DEFAULT_OPTS` 165 166 Enable alternate options for this specific use of `fzf`. Not set by default. 167 168 ```sh 169 export FZFGIT_DEFAULT_OPTS="--preview-window=':nohidden,right:65%:wrap'" 170 ``` 171 172 ### `FZFGIT_KEY` 173 174 Set default keybindings for all the `fzf` commands. See `man fzf` for a list of all possible options, or [here](https://github.com/junegunn/fzf/blob/97a725fbd0e54cbc07e4d72661ea2bd2bb7c01c1/man/man1/fzf.1#L648). 175 176 ```sh 177 # This variable does have a default value 178 export FZFGIT_KEY=" 179 --bind='ctrl-a:toggle-all' # toggle all selection 180 --bind='ctrl-b:execute(bat --paging=always -f {+})' # open in a pager 181 --bind='ctrl-y:execute-silent(echo {+} | pbcopy)' # copy the file to clipboard 182 --bind='ctrl-e:execute(echo {+} | xargs -o $EDITOR)' # open file in editor 183 --bind='ctrl-k:preview-up' # move the file preview up 184 --bind='ctrl-j:preview-down' # move the file preview down 185 --bind='alt-j:jump' # label jump mode, sort of like vim-easymotion 186 --bind='ctrl-0:top' # set cursor back to top 187 --bind='ctrl-s:toggle-sort' # toggle sorting 188 --bind='?:toggle-preview' # toggle preview 189 " 190 ``` 191 192 ### `FZFGIT_PREVIEW` 193 194 Preview command for the preview window in `fzf`. The order in which the preview is determined is: `bat`, `highlight`, `coderay`, `rougify`, `cat`. Not set by default. 195 196 ```sh 197 # Two different ones are given as examples to display the complexity it can be 198 # When specifying the command, be sure to use the {} placeholder 199 export FZFGIT_PREVIEW="([[ -f {} ]] && (bat --style=numbers --color=always {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2> /dev/null | head -200" 200 201 export FZFGIT_PREVIEW="cat -n {}" 202 ``` 203 204 ### `FZFGIT_DIFF_PAGER` 205 206 Customize diff preview on commands that display diff output. The initial value is read from from `git config core.pager`. Use this to specify something different. 207 208 ```sh 209 export FZFGIT_DIFF_PAGER="delta --diff-so-fancy --line-numbers" 210 ``` 211 212 ### `FZFGIT_BACKUP` 213 214 Top level directory where the current directory you are in can be backed up to. I am working on allowing specification of a path to a directory that you're currently not in. 215 216 ```sh 217 export FZFGIT_BACKUP="{$XDG_DATA_HOME}/gitbackup" 218 ```