Giter Site home page Giter Site logo

axonasif / dotsh Goto Github PK

View Code? Open in Web Editor NEW
28.0 2.0 21.0 86 KB

A fast dotfiles and system configuration installer optimized for Gitpod and power users

License: MIT License

Shell 98.91% Python 0.45% Dockerfile 0.64%
dotfiles gitpod gitpod-dotfiles fish neovim ssh tmux vscode bashbox bash

dotsh's Introduction

Introduction

A fast dotfiles and system-configuration installer optimized for Gitpod (can be used locally too). Is this another dotfiles-manager? Nope. In fact, it will try to detect your dotfiles-manager and install your raw files through it if you're using one. This is essentially a script, it is meant to be modularly customized from source code and compiled for convenience. You can even call it a "framework" if you like πŸ™ƒ

Quickstart for Gitpod

Note: You will be using your existing dotfiles repo, dotsh is only the installer.

Open this repo on Gitpod:

Open in Gitpod

Then run dotsh config on a terminal for interactive configuration wizard.

Or if you just want to try it out:

Learn more about dotfiles behaviour on Gitpod at https://www.gitpod.io/docs/config-dotfiles

Quickstart for local machine

Expand

Right now only Linux and MacOS is supported. In theory it could work on other *nix systems and maybe Windows, that said, the script could run fine but some special handling of how things are installed or configured needs to be done for other systems, please contribute if you're an user of an "unsupported" system.

Prerequisites

  • git
  • bash 4.3 or above

Linux

Install git with your distro's package manager. Generally bash version is not an issue on Linux distros.

MacOS

In MacOS you could install these via brew before proceeding.

# If you don't have homebrew already, otherwise skip this command
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

bash -lic 'set -m; brew install git bash'

exec bash -li # Reload bash

After you've made sure that the prerequisites are met, run:

# You may use your own fork instead
git clone https://github.com/axonasif/dotsh ~/.dotfiles
bash ~/.dotfiles/install.sh

Features

Most of these features stemmed from my personal needs. Another reason was to avoid repetitive work while answering some frequent questions at the Gitpod Discord server that required manual handcrafting for each scenario, an unified solution workaround was needed. I simply couldn't wait but try implementing them myself as long it's possible within the context of dotfiles layer on Gitpod. I really like how programmable Gitpod can be unlike anything out there! (although I wish it was more obvious).

Fast installation

binary_lazy_loading.compressed.mp4

The installation is highly parallelized. This leads to a reasonably fast Gitpod workspace startup. In the regular way it'd take at least 60seconds for my dotfiles installation itself, rendering dotfiles unusable. Some tricks are used to start fast without crashing things that rely on your custom-shell and tmux (for example) while they're being installed/configured in the background. One of the most important trick is lazy-loading binaries with (optional) locking.

Extra details

Lazy loading of binaries

A bash script is placed at an alternate place in $PATH or even the exact path of the real binary (where suitable) as a "shim". External programs (outside of dotsh process) will hit the "shim" and the "shim" will sleep until it receives a signal from dotsh (when necessary, otherwise no signals are required). This prevents the crash of programs that depends on a particular program. So for most of the cases, such dependant programs can get ahead of time with their tasks and only wait when necessary.

This is quite complicated under the hood due to race-conditions and filesystem operations, thankfully it didn't involve something like a fusefs implementaion which has it's own requirements (although that probably would've been easier to debug).

More details at here

Official issue: gitpod-io/gitpod#7592

Live testing of dotfiles and .gitpod.yml

dotsh_livetest.compressed.mp4

Testing out dotfiles or .gitpod.yml changes can be a lengthy and difficult process (something I have to do pretty much everyday). This live testing capability allowed me to quickly prototype the rest of dotsh logic, which would've been quite impossible otherwise.

Usage and details

For only testing dotfiles changes:

If you opened your dotsh repo on Gitpod:

Assuming your CWD is /workspace/dotsh, you can run bashbox livetest

If you didn't open dotsh but a different repo and want to test your dotfiles:

  • Go to ~/.dotfiles (where dotsh gets cloned by Gitpod) by running cd ~/.dotfiles
  • Now run bashbox livetest Tip: You could also do bashbox -C ~/.dotfiles livetest if you do not want to cd ~/.dotfiles.

For testing .gitpod.yml changes of a workspace (including dotfiles):

  • Run dotsh livetest from anywhere in your workspace.

Extra details

livetest command comes from Bashbox.sh as a package function. dotsh livetest command is an alias to bashbox -C <dotfiles-dir> livetest ws.

It shares almost everything from the host Gitpod workspace to the testing container, it may include:

  • /ide (mirror, doesn't affect the original one)
  • /workspace (ephemeral mirror, CoW via overlayfs)
  • /.supervisor (direct bind mount)
  • /usr/bin/gp (read-only)
  • /dev/fuse (for things like rclone mount)
  • /var/run/docker.sock (for using docker inside the testing container)
  • dotfiles (mirror)
  • Local network (to communicate with the IDE process, Gitpod API and expose ports to HOST)

This speeds up the process since we're just re-using the resources and is not expensive.

Tmux integration and the overall quick feedback makes it much more useful.

Note: This is only optimized for Gitpod and will not work elsewhere. You can also try run-gp which also supports running a Gitpod workspace locally.

Official issue: gitpod-io/gitpod#7671.

Tmux integration

gitpod.tmux

Using SSH or terminal in general without TMUX feels powerless! Gitpod got amazing SSH support and various different ways to SSH into its workspaces.

gitpod.tmux plugin is auto-installed for you, and Gitpod tasks are opened inside tmux via dotsh.

dotsh pervents Gitpod tasks to be executed in the regular bash terminals and spawns them inside tmux windows. After the task completion in a POSIX friendly shell, it'll auto switch to your favorite shell.

Integrated tmux usage from VSCode

VSCode is a great editor when you want to code from the browser, having an integrated tmux experience was must for me! All your new vscode terminals will get opened as tmux windows instead.

vscode_tmux_integration.compressed.mp4

Cross-workspace and local filesync

File sync is a crutial feature when working with ephemeral workspaces. This let's you sync files across workspaces or locally to individual workspaces. That means you could persist your login for CLI programs, cache big files and so on. It's gluing together rclone to accomplish this, nothing special on it's own.

This is easily one of the most wanted features on Gitpod. See /docs/PERSISTING_AUTH.md for examples of a few use-cases.

Usage

Run dotsh config rclone for initial setup of rclone (if you haven't yet).

To start syncing files, you can use:

# This will save and restore in the absolute static path.
dotsh filesync save /path/to/file another_file

To save a file from your $HOME directory and to dynamically auto restore it based on user home dir:

# Useful when you're using dotsh both locally and on Gitpod.
# -dh is short form of --dynamic-home argument.
# I'm saving docker.json to persist my login, so that I don't have to login every time.
cd $HOME
dotsh filesync -dh .config/docker.json

Why use rclone?

  • It's cross-platform.
  • Very powerful tool, has tons of options.
  • You own your data and have the flexibility to decide where to host it.

Official issue: gitpod-io/gitpod#9284

Optimized for CLI EDITOR(s)

Your favorite CLI editor is quickly auto installed for you. Also several common CLI tools, dependencies, editor plugins/presets are install and configured based on your preference in ahead of time. So you can easily get started with your own editor-config without worrying about tweaking the system.

The following editors are supported:

  • Emacs
  • Helix
  • NeoVim (I use this one)
  • Vim

A popular editor-preset (e.g. LunarVim [awesome config BTW!], Spacemacs) is installed unless your own config is detected. You can customize this from ./src/variables.sh.

Official issue: gitpod-io/gitpod#9323

Optimized for custom SHELL(s)

You can use you favorite shell on Gitpod task-terminals while perseving bash/posix compatibility with the Gitpod task scripts and also the shell-environment. You don't have to sacrifice the usability of custom shells!

Details

There is an universal issue with shells like fish or zsh, most tools (e.g. cargo) provide shell-environment scripts that are POSIX or bash-compatible and usually installed for the system login-shell. I personally use fish, had to make a bit of efforts for dailydriving it everywhere as the interactive shell. In a local PC, what usually happens is that fish or zsh inherits the environment variables from the GUI terminal-emulator process, which are stemmed from the system zygote process spawning other (*GUI) applications on top of the login shell. This is also why you'd be asked to re-login (display-manager) or reboot after changing your shell from chsh on a traditional *unix system to reflect the changes.

Fish

It will install fisher and install the following plugins via it:

You can modify this here.

Zsh

The following are auto-installed:

Official issue: gitpod-io/gitpod#10105

Easy SHH'ing through local terminal

gitpod_ssh_flow.compressed.mp4

Launch gitpod workspaces automatically inside a local terminal emulator via ssh:// without having to copy-paste manually!

Official issue: gitpod-io/gitpod#9323

Easy cross-platform package installation

We need not to worry about package management and leave it on the shoulders of nix, which is a very powerful package manager, unlike any other! Oh and, it's cross-platform too with tons of packages. Since Gitpod workspaces are ephemeral, using nix is even easier!

With dotsh, nix package installations are chunked into different levels to optimize terminal readiness. To add your own packages, edit the PACKAGES section on ./src/variables.sh

For example, here's how the level one packages array looks like on ./src/variables.sh:

declare nixpkgs_level_1+=(
    nixpkgs.ripgrep
    nixpkgs.fd
    nixpkgs.fzf
)

You can find packages at https://search.nixos.org/packages

Host aware multi-layer dotfiles installation

It will not overwrite some crutial host files (e.g. .bashrc, .gitconfig and etc.) while installing your dotfiles repos but virtually load your ones to preserve integrity of the host system. (if you're using a custom dotfiles-manager like chezmoi, you need to handle it through your dotfiles-manager)

For more details on this and an example raw dotfiles tree, check this

By default, it will use a basic symlinking mechanism unless you're using a dotfiles-manager, currently the following is recognized:

  • chezmoi

Extra goodies

  • Auto login into gh or glab CLI based on your repository context.
  • Shell completion for gp CLI.

Contributing and development

Open this repo on Gitpod:

Open in Gitpod

And use the livetesting mechanism for testing out your changes.

You can also run bashbox build --release for only compiling.

For viewing logs from the filesystem: less -FXR ~/.dotfiles.log

Also check docs/REFERENCE.md

Back story

dotsh is basically a pretty accumulation of some of my scattered scripts that I had before, now it's just a bit more organized and meaningful. And also the fact that the Gitpod community bought me encouragement for putting this together. I didn't have a proper dotfiles setup before, it was a mess but it's also true that I've been iterating over my dotfiles for the last ~9 months 😝. If you found it useful, let me know! (you can find me hanging around at the Gitpod Discord server)

I also personally hope that many of the things that I had to implement though Dotfiles would have an official and more robust implementation on Gitpod in the future! (Please react "πŸ‘" on the linked official issues BTW, that might help those getting prioritized)

This project was built with bashbox, and it's following libraries:

Generally, bash scripts are error prone, hard to debug and maintain. But it changes with bashbox!

dotsh's People

Contributors

axonasif avatar djsnipa1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dotsh's Issues

dotfiles::initialize should embed into specified existing files instead of replacing them to preserve functionality (i.e .bashrc, .gitignore and etc)

Right now dotfiles::initialize only has the ability to process .dotfilesignore file.

In order to preserve the functionality of existing files like .bashrc, .gitignore and others, we need to embed our own files into those of Gitpod and other places where we want to install our dotfiles.

Will have to introduce another run-config-file for dotfiles::initialize where we can specify files to be embedded into existing files.

My git commits are from you

Hello,

I have been using these dotfiles for gitpod and they are amazing! Thank you very much!

However, I've just started noticing that anytime I use gitpod and make a commit, they are by you and not me. Example here

I'm not sure exactly how it's happening because it says my git config --global settings are my name and email. Any help would be greatly appreciated.

Thanks again!

How to default VS Code terminal to fish?

First of all, thanks for this! I found your post(s) on Discord, and it seemed like exactly what I was looking for (after spending several hours pounding my head against GitPod's docs).

πŸ™‡πŸ½

By any chance do you know how to make VS Code default consistently to fish without manual effort?

I found advice to put this in settings.json…

"terminal.integrated.shell.linux": "/usr/bin/fish" 

…but of course, when I make that change in one GitPod workspace, that doesn't propagate to new workspaces. Do I have to add my own settings.json hack, or is this something your dotfiles can already be configured to handle?

Forked and used the Dotfiles with gitpod - no port 22000 open

Hey Axon,
I saw your talk on Community Office Hours: dotfiles w/ SSH and It got me interested.
I followed the steps and I can't see the port you opened 22000. I have a free gitpod plan - is this maybe a reason?

Do I need to enter my github information somewhere?
My end goal is to use lunarVim and my .vimrc file with gitpod to have my dev setup always with me.

Kind regards Marco

Connection Closed

Hi! I tried adding this to as my dot files for Gitpod, when I try to connect via ssh it closes my connection straight a way, if I remove it as my dotfiles, I can connect with no issue:

Welcome to Gitpod: Always ready to code. Try the following commands to get started:

	gp tasks list         List all your defined tasks in .gitpod.yml
	gp tasks attach       Attach your terminal to a workspace task

	gp ports list         Lists workspace ports and their states
	gp stop               Stop current workspace
	gp help               To learn about the gp CLI commands

For more information, see the Gitpod documentation: https://gitpod.io/docs
Connection to ******-******-9jtjdrylz8h.ssh.ws-us79.gitpod.io closed.

Any ideas what might be wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.