Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A lightweight workspace manager for the shell

License

NotificationsYou must be signed in to change notification settings

jamesob/desk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

buildJoin the chat at https://gitter.im/jamesob/desk

Lightweight workspace manager for the shell.

Desk makes it easy to flip back and forth between different project contexts inyour favorite shell. Change directory, activate a virtualenv or rvm, loadin domain-specific aliases, environment variables, functions, arbitrary shell files,all in a single command.

Instead of relying onCTRL-R to execute and recall ("that command's gottabe here somewhere..."), desk helps shorten and document those actions withshell aliases and functions, which are then namespaced under a particulardesk.

Because Deskfiles are just enriched shell scripts, the possibilities areendless. For example, when doing work on AWS I have desksecurely load AWS API keys into environment variables viapass -- no effort on my part, and norisk of accidentally persisting that sensitive information to a history file.

I have a hard time calling this a "workspace manager" with a straightface -- it's basically just a shell script that sources another shell script in a new shell.But I often find myself working in multiple different code trees simultaneously:the quick context switches and namespaced commands that desk facilitateshave proven useful.

There are no dependencies other thanbash. Desk is explicitly tested withbash,zsh, andfish.

◲  desk 0.6.0Usage:    desk        List the current desk and any associated aliases. If no desk        is being used, display available desks.    desk init        Initialize desk configuration.    desk (list|ls)        List all desks along with a description.    desk (.|go) [<desk-name-or-path> [shell-args...]]        Activate a desk. Extra arguments are passed onto shell. If called with        no arguments, lookfora Deskfilein the current directory. If not a        recognized desk, try as a path to directory containing a Deskfile.    desk run<desk-name><cmd>        Run acommand within a desk's environment then exit. Think'$SHELL -c'.    desk edit [desk-name]        Edit (or create) a deskfile with the name specified, otherwise        edit the active deskfile.    desk help        Show this text.    desk version        Show version information.Since desk spawns a shell, to deactivate and "pop" out a desk, yousimply need to exit or otherwise end the current shell process.

For example, given this deskfile (~/.desk/desks/tf.sh):

# tf.sh## Description: desk for doing work on a terraform-based repository#cd~/terraform-repo# Set up AWS env variables: <key id> <secret>set_aws_env() {export AWS_ACCESS_KEY_ID="$1"export AWS_SECRET_ACCESS_KEY="$2"}# Run `terraform plan` with proper AWS var configplan() {  terraform plan -module-depth=-1 \    -var"access_key=${AWS_ACCESS_KEY_ID}" \    -var"secret_key=${AWS_SECRET_ACCESS_KEY}"}# Run `terraform apply` with proper AWS var configalias apply='terraform apply'

we'd get

$ desk. tf$ desktfdeskfor doing work on a terraform repo  set_aws_env   Set up AWS env variables:<key id><secret>  plan          Run`terraform plan` with proper AWS var config  apply         Run`terraform apply` with proper AWS var config

Basically, desk just associates a shell script (name.sh) with a name. Whenyou calldesk . name, desk drops you into a shell wherename.sh has beenexecuted, and then desk extracts out certain comments inname.sh for usefulrendering.

Installing

With homebrew

brew install desk

With curl

Assuming~/bin exists and is on the PATH... otherwise, substitute/usr/local/binand addsudo as needed.

  1. curl https://raw.githubusercontent.com/jamesob/desk/master/desk > ~/bin/desk
  2. chmod +x ~/bin/desk

With git

  1. git clone git@github.com:jamesob/desk.git && cd desk && sudo make install

After that, rundesk init and start adding deskfiles with eitherdesk edit [deskfile name]or by manually adding shell scripts into your deskfiles directory (by default~/.desk/desks/).

Enabling shell extensions

NB: Shell extensions are automatically enabled if Desk is installed via Homebrew.

Using bash

  1. Addsource /path/to/desk/repo/shell_plugins/bash/desk to your.bashrc.

Using fish

mkdir-p ~/.config/fish/completionscp /path/to/desk/repo/shell_plugins/fish/desk.fish ~/.config/fish/completions

Using zsh

  1. Addfpath=(/path/to/desk/repo/shell_plugins/zsh $fpath) to your.zshrc.

Optionally, use one of the zsh plugin frameworks mentioned below.

  1. make oh-my-zsh from within this repo. This sets up a symlink.

or

  1. cd ~/.oh-my-zsh/custom/plugins
  2. git clone git@github.com:jamesob/desk.git /tmp/desk && cp -r /tmp/desk/shell_plugins/zsh desk
  3. Add desk to your plugin list

UsingAntigen

  1. Addantigen bundle jamesob/desk shell_plugins/zsh to your.zshrc
  2. Open a new terminal window. Antigen will clone the desk repo and add it to your path.

Usingzgen

  1. Addzgen load jamesob/desk shell_plugins/zsh to your.zshrc with your other load commands
  2. rm ~/.zgen/init.zsh
  3. Start a new shell; zgen will generate a newinit.zsh and automatically clone the desk repository for you and add it to your path.

Deskfile rules

Deskfiles are just shell scripts, nothing more, that live in the desk config directory.Desk does pay attention to certain kinds of comments, though.

  • description: you can describe a deskfile by including# Description: ...somewhere in the file.

  • alias and function docs: if the line above an alias or function is acomment, it will be used as documentation.

Deskfiles

Deskfiles are just shell scripts at the root of a project directory thatadhere to the conventions above. These can be put into version control toformalize and ease common development tasks like running tests or doinglocal builds.

For example, if we have some directory or repository calledmyproject, ifwe createmyproject/Deskfile, we'll be able to do any of the following:

$ desk go /path/to/myproject/$ desk go /path/to/myproject/Deskfilemyproject/ $ desk go.myproject/ $ desk go

Sharing deskfiles across computers

Of course, the desk config directory (by default~/.desks) can be a symlinkso that deskfiles can be stored in some centralized place, like Dropbox,and so shared across many computers.

Using a non-default config location

By default, desk configuration lives in~/.desk ($DESK_DIR) and deskfileslive in~/.desk/desks ($DESK_DESKS_DIR). If you want to use some otherlocation, specify as much indesk init and then ensure you set$DESK_DIRand/or$DESK_DESKS_DIR to match in your shell's rc file.

Shortening invocation

Typingdesk . frequently can get old; personally, I like to alias this with

alias d.='desk .'

in my shell rc file.

Usage with OS X

Desk won't work when used strictly with~/.bash_profile on OS X's terminal, sincethe content of~/.bash_profile is only executed onlogin, not shell creation, asexplainedhere.

My recommendation is to use~/.bashrc as your general-purpose config file, then simplyhave~/.bash_profile point to it:

# ~/.bash_profileif [-f~/.bashrc ];thensource~/.bashrcfi

Related projects

  • godesk by @hamin: a desk launcher with fuzzy filtering

Tips accepted

18ehgMUJBqKc2Eyi6WHiMwHFwA8kobYEhy

BTC:18ehgMUJBqKc2Eyi6WHiMwHFwA8kobYEhy

Half of all tips will be donated toan organization providing aid to Syrian refugees.

Donations made on behalf of tippers

dateamountorganization
2015-11-18$1.07http://moas.eu
2016-11-14$21.00http://moas.eu

[8]ページ先頭

©2009-2025 Movatter.jp