{"id":15648011,"url":"https://github.com/gregnavis/bash-ctx","last_synced_at":"2025-04-30T13:50:37.473Z","repository":{"id":30855131,"uuid":"34412655","full_name":"gregnavis/bash-ctx","owner":"gregnavis","description":"Make working on multiple projects a breeze!","archived":false,"fork":false,"pushed_at":"2018-04-06T10:05:56.000Z","size":18,"stargazers_count":42,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T16:39:32.727Z","etag":null,"topics":["bash"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gregnavis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-22T19:58:27.000Z","updated_at":"2022-12-05T21:31:24.000Z","dependencies_parsed_at":"2022-09-20T23:00:27.683Z","dependency_job_id":null,"html_url":"https://github.com/gregnavis/bash-ctx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregnavis%2Fbash-ctx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregnavis%2Fbash-ctx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregnavis%2Fbash-ctx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gregnavis%2Fbash-ctx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gregnavis","download_url":"https://codeload.github.com/gregnavis/bash-ctx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251714819,"owners_count":21631795,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash"],"created_at":"2024-10-03T12:22:41.401Z","updated_at":"2025-04-30T13:50:37.378Z","avatar_url":"https://github.com/gregnavis.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bash-ctx - Make working on multiple projects a breeze!\n\nI spend most of my time in a terminal and frequently issue commands that are\n_almost_ similar. Unfortunately, _almost_ makes a big difference. Here are a\nfew things that can go wrong:\n\n* You rebase a branch on top of `master` instead of `develop` because another\n  project you're working on doesn't have `develop` and you were confused.\n* You start the development server with wrong parameters as they're slightly\n  different for every project.\n* You type `bundle exec rails routes | grep \u003cpattern\u003e` only to discover this is\n  a Rails 4 project and you should have used `rake` instead of `rails`.\n\n`bash-ctx` helps you avoid such annoyances by helping you define\nproject-specific aliases and configuration variables. You can use it to:\n\n* Start the development server with `.start` - doesn't matter whether it's\n  Rails, Django, or any other framework.\n* Run the tests with `.test` - again, no need to think about which tool the\n  current project is using.\n* Pull `master` and rebase the current branch on top of it just by calling\n  `.update`.\n\n## Installation\n\nDownload and extract https://github.com/grn/bash-ctx/archive/master.zip and run\n`install`:\n\n```\n$ wget https://github.com/grn/bash-ctx/archive/master.zip\n$ unzip master.zip\n$ cd bash-ctx-master\n$ ./install\n```\n\nThis will install `bash-ctx` in `~/.bash-ctx`. Remember to load it in your\n`.bashrc`:\n\n```bash\n# Load bash-ctx if available.\nif [ -r \"${HOME}/.bash-ctx/bash-ctx\" ]; then\n  source \"${HOME}/.bash-ctx/bash-ctx\"\nfi\n```\n\n## Basic Concepts\n\nThe two essential concepts in `bash-ctx` are:\n\n* Contexts - they represent project-specific settings and are stored in\n  `~/.bash-ctx/ctx`. Each context is a file with bash commands to execute when\n  entering the context.\n* Libraries or libs - common pieces of functionality you can share across your\n  contexts. For example, all your Rails 5 projects can just use the `rails5` lib\n  instead of redefining the same functions and aliases over and over again.\n\nYou first create a context and then enter it. If you enter a context then its\nname is passed in an environment variable to a newly created bash child process\n(instead of just sourcing it in the calling process). Your `.bashrc` will then\nsource the right context file. The benefit of this approach is that you avoid\npolluting your top-level shell with context-specific stuff and keep contexts\nseparated.\n\n## Usage\n\nCreate a new context for your project:\n\n```\nctx new my-project\n```\n\nEdit the newly created context file with:\n\n```\nctx edit my-project\n```\n\nYou can add project specific aliases (e.g. `alias .deploy='git push heroku'`),\nset environment variables, change directories, and so on.\n\nIn order to enter the context run:\n\n```\nctx enter my-project\n```\n\nThis will launch a new `bash` shell and run the context script you created\nabove. When you're done you can just quit this shell and return to the parent\nshell (where you called `ctx enter`).\n\nYou can also list all contexts with `ctx list`:\n\n```\nctx list\nmy-context\n```\n\n## Example Context File\n\n```\nctx_libs git rails5\n\n# I often need to reset accounts but wouldn't like to reset the other tables.\nfunction .cleanup() {\n  .run 'Account.update_all status: 0'\n}\n\ncd ~/Projects/MyProject\nctx_libs tmux\n```\n\n## Libs\n\nLibs are small shell script libraries that you can share across projects. It's\nan easy way to define aliases, functions, and set environment variables.\nCreating your own lib is easy. Just run `ctx lib \u003cname\u003e` and call `ctx_libs\n\u003cname\u003e` in your context file to include the lib in it.\n\nBelow is a list of provided libs.\n\n### `git`\n\nAllowed commands:\n\n* `.update [\u003cremote\u003e] [\u003cbranch\u003e]` - stash changes, pull the specified remote\n  branch (as defined in `$CTX_GIT_ORIGIN` and `$CTX_GIT_BRANCH` which default to\n  `origin` and `master`) and rebase the current branch on top of it.\n  default) from the specified remote and rebase the current branch on top of it.\n* `.squash \u003cn\u003e` - squash the last `n` commits.\n* `.amend` - edit the current commit message (`git commit --amend -v`).\n* `.fix` - amend the current commit with the changes from the work tree\n  (equivalent of `git commit -a --amend -C HEAD`).\n* `.commit \u003cmessage\u003e` - equivalent of `git commit -m \u003cmessage\u003e`.\n\nAllowed configuration variables:\n\n* `CTX_GIT_ORIGIN` - the default origin. Defaults to `origin`.\n* `CTX_GIT_BRANCH` - the default branch from origin. Defaults to `master`.\n\n### `rails4` and `rails5`\n\nAll commands are prefixed by `bundle exec` and use `rake` (Rails 4) or `rails`\n(Rails 5):\n\n* `.migrate` - `rails db:migrate`\n* `.rollback` - `rails db:rollback`\n* `.seed` - `rails db:seed`\n* `.reset` - `rails db:reset`\n* `.start [\u003cargs\u003e]` - `rails s \u003cargs\u003e`\n* `.run [\u003cargs\u003e]` - `rails runner \u003cargs\u003e`\n* `.console [\u003cargs\u003e]` - `rails console \u003cargs\u003e`\n* `.database [\u003cargs\u003e]` - `rails dbconsole \u003cargs\u003e`\n* `.generate [\u003cargs\u003e]` - `rails generate \u003cargs\u003e`\n* `.destroy [\u003cargs\u003e]` - `rails destroy \u003cargs\u003e`\n* `.test [\u003cargs\u003e]` - `rails test \u003cargs\u003e`\n* `.rspec [\u003cargs\u003e]` - `rspec \u003cargs\u003e`\n* `.routes` - `rails routes`\n* `.routes \u003cpattern\u003e` - `rails routes | grep \u003cpattern\u003e`\n\n### `tmux`\n\nDoes not define any commands but runs `tmux` upon inclusion via `ctx_libs`\nunless already in a `tmux` session.\n\n## Inspirations\n\nUpon entering a context you can:\n\n* Go to the project directory.\n* Start a `screen` or `tmux` session.\n* Set project-specific environment variables (e.g. `PATH` or the prompt).\n* Set project- or client-specific aliases and functions.\n* Start some services in the background (e.g. Redis, Guard).\n* Activate a Python virtual environment.\n* Use an rbenv gem set.\n\n## Bugs, Feature and Enhancement Requests\n\nI'd love to hear your feedback! If something doesn't work, or should work\ndifferently, just file an issue at https://github.com/grn/bash-ctx/issues/new.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregnavis%2Fbash-ctx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgregnavis%2Fbash-ctx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgregnavis%2Fbash-ctx/lists"}