• Stars
    star
    2,514
  • Rank 18,250 (Top 0.4 %)
  • Language
    Shell
  • License
    MIT License
  • Created about 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightweight workspace manager for the shell

â—² desk

build Join 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 in your favorite shell. Change directory, activate a virtualenv or rvm, load in domain-specific aliases, environment variables, functions, arbitrary shell files, all in a single command.

Instead of relying on CTRL-R to execute and recall ("that command's gotta be here somewhere..."), desk helps shorten and document those actions with shell aliases and functions, which are then namespaced under a particular desk.

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

I have a hard time calling this a "workspace manager" with a straight face -- 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 facilitates have proven useful.

There are no dependencies other than bash. Desk is explicitly tested with bash, zsh, and fish.

â—²  desk 0.6.0

Usage:

    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, look for a Deskfile in the current directory. If not a
        recognized desk, try as a path to directory containing a Deskfile.
    desk run <desk-name> <cmd>
        Run a command 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, you
simply 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 config
plan() {
  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 config
alias apply='terraform apply'

we'd get

$ desk . tf
$ desk

tf
desk for 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. When you call desk . name, desk drops you into a shell where name.sh has been executed, and then desk extracts out certain comments in name.sh for useful rendering.

Installing

With homebrew

brew install desk

With curl

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

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

With git

  1. git clone [email protected]:jamesob/desk.git && cd desk && sudo make install

After that, run desk init and start adding deskfiles with either desk 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. Add source /path/to/desk/repo/shell_plugins/bash/desk to your .bashrc.

Using fish

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

Using zsh

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

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

Using oh-my-zsh

  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 [email protected]:jamesob/desk.git /tmp/desk && cp -r /tmp/desk/shell_plugins/zsh desk
  3. Add desk to your plugin list

Using Antigen

  1. Add antigen 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.

Using zgen

  1. Add zgen 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 new init.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 a comment, it will be used as documentation.

Deskfiles

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

For example, if we have some directory or repository called myproject, if we create myproject/Deskfile, we'll be able to do any of the following:

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

Sharing deskfiles across computers

Of course, the desk config directory (by default ~/.desks) can be a symlink so 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 deskfiles live in ~/.desk/desks ($DESK_DESKS_DIR). If you want to use some other location, specify as much in desk init and then ensure you set $DESK_DIR and/or $DESK_DESKS_DIR to match in your shell's rc file.

Shortening invocation

Typing desk . 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, since the content of ~/.bash_profile is only executed on login, not shell creation, as explained here.

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

# ~/.bash_profile

if [ -f ~/.bashrc ]; then
   source ~/.bashrc
fi

Related projects

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

Tips accepted

18ehgMUJBqKc2Eyi6WHiMwHFwA8kobYEhy

BTC: 18ehgMUJBqKc2Eyi6WHiMwHFwA8kobYEhy

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

Donations made on behalf of tippers

date amount organization
2015-11-18 $1.07 http://moas.eu
2016-11-14 $21.00 http://moas.eu

More Repositories

1

tinychain

A pocket-sized implementation of Bitcoin
Python
1,448
star
2

coldcore

Trust-minimized Bitcoin wallet
Python
133
star
3

docker-bitcoind

A configurable docker image for bitcoind
Python
87
star
4

Miser

Programmatic budgeting
Python
58
star
5

clii

Python 3.7+ function annotations -> CLI
Python
43
star
6

simple-ctv-vault

A simple vault structure using OP_CTV
Python
42
star
7

mempool.work

Summary of mempool design, challenges, and proposals (re: fees)
41
star
8

assumeutxo-docs

Documentation for Bitcoin's assumeutxo proposal
16
star
9

bitcoin-github-scrape

Haphazard scripts for scraping bitcoin/bitcoin data from GitHub
8
star
10

txture

The 30 second blog engine for (Clojure) hackers
Clojure
7
star
11

verystable

A python toolkit for unstable bitcoin things
Python
6
star
12

opvault-demo

An example wallet using OP_VAULT
Python
6
star
13

omgwebapp

A minimal flask/react/webpack boilerplate internet starter kit thing
JavaScript
6
star
14

delving-bitcoin-archive

A public archive of delvingbitcoin.org
4
star
15

create.clj

A driver for the iRobot Create, written in Clojure. Not complete, by any means.
C
3
star
16

discourse-archive

Provides a simple archive of Discourse content
Python
3
star
17

whatup.sh

Get a quick overview of what's happening on a Unix system
Shell
3
star
18

ackr

Haphazard tool for reviewing Bitcoin Core PRs
Python
3
star
19

biketrip

The source code to a Jekyll site about our bike trip to SF.
JavaScript
3
star
20

bashwords

BASH integrated vocabulary training.
Python
2
star
21

id3renamer

Rename MP3s based on ID3 with Python.
Python
2
star
22

prom-exporter-basic

A Prometheus exporter for basic system metrics with no dependencies
Python
2
star
23

pwdy

A command-line password manager.
Python
2
star
24

mnty

A small utility for managing sshfs mount profiles.
Python
2
star
25

sicp

Completed exercises from Sussman-Abelson's Structure and Interpretation of Computer Programs
Scheme
2
star
26

exploring-git

I explore the git source, take notes
1
star
27

uncertainties

making experimental physics a little less horrible
Python
1
star
28

kali

A horrifying build tool for LAMPDrupal stacks.
Python
1
star
29

icpc-problems

A collection of ACM ICPC problems I've completed
Java
1
star
30

deltaT

My txture blog
Clojure
1
star
31

jrni

An over-under-engineered flat journal management system in rust
Rust
1
star
32

droid-arch-tethering

A script to set up Droid tethering for clients running Arch Linux.
Python
1
star
33

weekend-hackups

An excuse to make some shit.
1
star
34

transcraper

Scrape your information from financial institutions
Python
1
star
35

clibrarian

Your CLI history over HTTP
CoffeeScript
1
star
36

jamesob.github.io

CSS
1
star
37

gandi-ddns

Declarative dynamic DNS with gandi.net
Python
1
star
38

cryptopals-solutions

Cryptopals solutions in Rust
Rust
1
star
39

jamesob.github.com

JavaScript
1
star