I like this `bin/replace` script, but I've recently switched from `ag`
to [ripgrep](https://github.com/BurntSushi/ripgrep). This checks for the
presence of `rg` and uses it in `bin/replace`, passing the correct
parameter to disable colors.
The Github `hub` utilty has added a `pr` subcommand, which takes
precedence over `git-pr` in execution order, so this script is no longer
accessible with `git pr` or `hub pr`.
This change prevents chained commands from continuing execution if the
`git merge` is operation would be unsuccessful such as a common
operation when a feature branch is ready to be merged and pushed:
```
git merge-branch && git push origin
```
If the origin/master and the local master have any difference, we return
status 1 and stop execution rather then emit a false success.
h/t: @croaky
Fix#563.
To [append a project's local `bin/` directory to `$PATH`][dotfiles],
the dotfiles check for the existence of a special directory: `git/.safe`.
This commit is inspired by [thoughtbot/suspenders#837][#837]:
> The idea behind the .git/safe is that I run it manually and explicitly
> after I trust the directoy and the team behind the project.
> Creating it as part of the setup script defeats the point of that. Doing
> so without explcitly telling the user comes across as sneaky, perhaps.
> (I do expect all devs to read setup scripts before running them -- but I
> also know that they do not!)
> Switch this script to inform the user that they have no `.git/safe`
> directory but might like to make one.
Since suspenders may no longer mark projects safe by default, this
commit introduces the `git trust-bin` command to do so.
[dotfiles]: af75a673b1/zsh/configs/post/path.zsh (L9-L10)
[#837]: https://github.com/thoughtbot/suspenders/pull/837
I added this four years ago but haven't been using it.
Not common enough to be included in company-wide dotfiles?
Can move to personal dotfiles if desired.
Problem:
Currently the `for` in bash will break up lists by whitespace, so if a
filename has a space in it the `for` will break it up incorrectly.
AG will separate the files with a newline character, so this temporarily
overwrites the `IFS` to be used correctly for this use case.
[Docs](https://bash.cyberciti.biz/guide/$IFS)
The existing implementation of the `replace` script does not work on
GNU/Linux due to differences in the implementation of `sed`. This change
reworks the process of the replacement to create temporary files,
apply the changes to the files, and then move them into place. It will
improve the script's portability for more OSes.
**Bring executables into better shellcheck compliance**
While evaluating linting and testing options for our shell
configuration, a run of Shellcheck against our executables turned up
some places where we could use more consistent syntax across our
executables, such as always using a shebang or quoting `$HOME` when we
build up a larger directory.
**Update syntax for zsh functions and completions**
A few changes found while linting zsh configs with shellcheck:
* thoughtbot's [style guide] [guide] calls for `$(..)` over backticks
when capturing command output
* use `-gt` to test array length in arguments
[guide]: https://github.com/thoughtbot/guides/tree/master/best-practices
The `ranch` subcommand is annoying to skip and adds clutter to our
system, which only encourages people not to use our dotfiles as a base.
Remove it to get customizability back.
Sometimes when typing `git branch` I leave off the leading `b`, leading
to the boring message:
> git: 'ranch' is not a git command. See 'git --help'.
This adds a custom `git ranch` command with a friendlier funny message.
Bundler 1.8+ added support for git-style subcommands. Any scripts
starting with `bundler-` in your path are executable as bundler
subcommands.
This adds `search` as a subcommand that uses `ag` to search for a string
among all gems in your bundle (default) or optionally a specific gem.
I've found this useful for finding the source of puzzling deprecations,
finding what gem provides a method, and other various things.
The existing script would fail if run from within tmux as the default
behavior would cause a nested tmux session which is bad. This update
detects if the current context is within tmux and properly handles this
by creating a detached session and switching to it as needed.
The idea with this is for tat to behave correctly regardless of context,
which I believe this update achieves. Existing users and workflows all
work identically, but now this adds support for a workflow that remains
within tmux at all times.
I prefer to remain within tmux all the time, rather than falling back to
the shell, navigating to another directory, and then creating the
session from there. With this update, I split a pane in the current tmux
window, navigate to the directory for the new session, and use `tat` to
open (or attach) to the new-session without ever leaving tmux.
I actually [have a binding that I use for this][], `C-b` (I am
"breaking" out a new session), that is mapped to `bind C-b send-keys
'tat && exit' 'C-m'`, which also cleans up the pane.
The reason for wanting this workflow is I am pretty strict about keeping
a tmux session focused to a single project (~ maps to a git repo). I
regularly want to reference another app and will use this workflow to
quickly open that project in a new session.
A "detached" session is one which has no clients attached. [From the man
page entry][] for `new-session`: `The new session is attached to the
current terminal unless -d is given.` This essentially creates it in the
background, preventing nesting. Then the script can attach the current
client using the `switch-client` command.
[have a binding that I use for this]: 01cc928672/tmux/tmux.conf (L89)
[From the man page entry]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/tmux.1?query=tmux&sec=1
https://github.com/ggreer/the_silver_searcher
* ag is faster than ack
* ag searches all files by default (but still ignores gitignored files). This
removes the need for ack's `--type-add=` options.
* The command is 33% shorter than ack!
* Use a regular alias to make `s` short for `rspec`
* Use an `rspec` shell function to route to zeus when appropriate
* Removes confusion from `s` working differently than `rspec`
* Removes need to use a special alias to get zeus working
staging:
staging console
staging migrate
staging process
staging open
watch staging ps
staging tail
production:
production backup
production console
production migrate
production open
watch production ps
production tail
load-backup-into:
load-backup-into staging
load-backup-into development
Notes on the last command:
* Copy latest production database backup into development database using
preferred pgbackups + pg_restore method recommended by Heroku.
* Do not assume local development database name.
* Get local database name from config/database.yml.
* This did not previously exist in dotfiles.
Supporting change for these commands:
* Add ~/.bin to the PATH.
https://github.com/thoughtbot/dotfiles/pull/76
I've been experimenting with a workflow where I only run long-running
processes in tmux. Examples:
zeus start
foreman start
rake
tmux (or screen) are good at that: maintaining a long-running process
across shell sessions.
Instead of opening another tmux pane for vim and another for git
commands, Rails generators, test runs, etc., I do all of that outside of
tmux in my normal shell window. Those are all targeted, quick, actions.
They are what I am doing *right now*. It's my workspace.
While experimenting with this process, I noticed, I do jump into tmux
more often. Therefore, I wanted a shorter command for attaching to the
tmux session with the same name as the current directory.
After you commit a bug fix to a feature branch, find out if the code
you changed to fix the bug is in files that change often:
git-churn
If the buggy code changes often, find smells and refactor them. Separate
the parts that change often from the parts that don't.
Conversely, avoid refactoring areas with low churn. Refactoring changes
code, and with each change, you risk introducing new bugs.
Example:
[feature-branch][~/dev/rails-app] churn
2 app/controllers/accepts_controller.rb
2 config/database.yml
4 app/helpers/application_helper.rb
4 config/application.rb
9 spec/models/user_spec.rb
9 spec/spec_helper.rb
12 spec/requests/dashboard_spec.rb
13 spec/models/feedback_spec.rb
19 app/models/feedback.rb
21 app/models/user.rb