Skip to content

Commit

Permalink
feat: add ujust, refactor shell change tasks
Browse files Browse the repository at this point in the history
This adds a little shim, `/usr/bin/ujust`, to run,
`just --unstable --justfile /usr/share/ublue-os/justfile`.

I think this is a much cleaner way to run our `just` tasks than putting
a `~/.justfile` in the home directory, for a number of reasons. One of
them is that this does not require aliasing `just=just --unstable`, and
another is that a user can actually have their own `~/.justfile` with no
regard for including our global one.

I didn't remove the `just` aliases from the shell dotfiles, because I'm
not sure what breaking changes that might cause -- documentation, for sure,
but also does yafti or anything else depend on that?

Also to be honest I'm not sure where the default just alias comes from.
I didn't actually look yet :P

I did this because I realized how much duplicate code and room for errors
I had in the shell change tasks I rewrote -- I think it's much better to
write a task with an argument, `just chsh /usr/bin/newshell`, and then
call that from other tasks that need to change the shell. However, I saw
the limitations of using shell aliases to add the `--unstable` flag quite
quickly -- my sub-just-invocations became longer than I'd like them to be.
See https://just.systems/man/en/chapter_40.html and note how much nicer
that is than `just --unstable --file /usr/share/ublue-os/justfile`...

I'd definitely like to see others' thoughts on this! Feel free to ping me
on Discord @bri9.

--bri
  • Loading branch information
b- committed Oct 13, 2023
1 parent 09e8fe2 commit edcf66a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
37 changes: 27 additions & 10 deletions just/custom.just
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# vim: set ft=make :

uid := `id -u`

# Run a one minute system benchmark
benchmark:
echo 'Running a 1 minute benchmark ...'
Expand All @@ -23,6 +25,10 @@ aqua:
printf '\n export PATH="${AQUA_ROOT_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/aquaproj-aqua}/bin:$PATH"\n'
printf '\n=> see https://aquaproj.github.io/docs/tutorial for more info\n'

# Set shell (back) to bash
bash:
ujust chsh /bin/bash

# Install Homebrew for Linux
brew:
echo "Installing homebrew ..."
Expand All @@ -38,18 +44,31 @@ brew-shell:
if grep -q "linuxbrew" $HOME/.zprofile
then
echo "Brew configuration already present in .zprofile"
else
else
echo "Adding Brew configuration to .zprofile"
echo 'eval "$(/var/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> $HOME/.zprofile
fi
if grep -q "linuxbrew" $HOME/.bash_profile
then
echo "Brew configuration already present in .bash_profile"
else
else
echo "Adding Brew configuration to .bash_profile"
echo 'eval "$(/var/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> $HOME/.bash_profile
fi

# Change the user's shell
chsh shell:
#!/usr/bin/env bash
set -euo pipefail
CURRENT_SHELL="$(cat /etc/passwd | grep ":{{uid}}:" | cut '-d:' '-f7')"
if [ "{{shell}}" = "${CURRENT_SHELL}" ] ; then
printf "Your shell is already set to %s.\n" "${CURRENT_SHELL}"
else
sudo usermod $USER --shell "{{shell}}"
CURRENT_SHELL="$(cat /etc/passwd | grep ":{{uid}}:" | cut '-d:' '-f7')"
printf "%s's shell is now %s.\n" "$USER" "${CURRENT_SHELL}"
fi

# Enable Cockpit for web-based system management | https://cockpit-project.org/
cockpit:
echo 'Enabling Cockpit'
Expand Down Expand Up @@ -107,8 +126,7 @@ distrobox-universal:

# Switch to the fish shell
fish:
sudo usermod $USER --shell /usr/bin/fish
printf "${USER}'s shell is now %s." "$(cat /etc/passwd | grep ":$UID:" | cut '-d:' '-f7')"
just --unstable --justfile {{justfile()}} chsh /usr/bin/fish

# Install recommended GNOME extensions
gnome-extensions:
Expand Down Expand Up @@ -154,12 +172,12 @@ nix-devbox-global:

# Enable podmansh as user shell (EXPERIMENTAL)
podmansh:
#!/usr/bin/env bash
sudo mkdir -p /etc/containers/systemd/users/${UID}
sudo cp /usr/share/ublue-os/quadlets/podmansh.container /etc/containers/systemd/users/${UID}/podmansh.container
sudo usermod $USER --shell /usr/bin/podmansh
printf "${USER}'s shell is now %s." "$(cat /etc/passwd | grep ":$UID:" | cut '-d:' '-f7')"
just --unstable --justfile {{justfile()}} chsh /usr/bin/podmansh
podman pull ghcr.io/ublue-os/ubuntu-toolbox:latest

systemctl --user daemon-reload
systemctl --user stop podmansh.service
systemctl --user start podmansh.service
Expand All @@ -186,7 +204,7 @@ pytorch:
--no-browser --allow-root"

# Run Tensorflow
tensorflow:
tensorflow:
echo 'Follow the prompts and check the tutorial: https://www.tensorflow.org/tutorials/quickstart/beginner'
podman pull docker.io/tensorflow/tensorflow:latest
podman run -it -p 8888:8888 docker.io/tensorflow/tensorflow:latest-jupyter # Start Jupyter server
Expand Down Expand Up @@ -217,8 +235,7 @@ yafti:

# Switch to the zsh shell
zsh:
sudo usermod $USER --shell /usr/bin/zsh
printf "${USER}'s shell is now %s." "$(cat /etc/passwd | grep ":$UID:" | cut '-d:' '-f7')"
just /usr/bin/zsh

docker:
sudo systemctl enable --now docker
Expand Down
2 changes: 2 additions & 0 deletions usr/bin/ujust
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
/usr/bin/just --unstable --justfile /usr/share/ublue-os/justfile

0 comments on commit edcf66a

Please sign in to comment.