Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Commit

Permalink
feat: unified studio cli
Browse files Browse the repository at this point in the history
  • Loading branch information
tulilirockz committed Mar 6, 2024
1 parent 588e627 commit 8386ea0
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 209 deletions.
33 changes: 0 additions & 33 deletions config/files/shared/bin/pwjack-config

This file was deleted.

9 changes: 9 additions & 0 deletions config/files/shared/bin/studio
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env -S nu

use ../libexec/atomic-studio-cli/mod.nu *

# The main Atomic Studio CLI.
# You can use this to run Atomic Studio-specific commands
def "main" [] {
echo "Usage: studio <command>."
}
16 changes: 0 additions & 16 deletions config/files/shared/bin/studio-commands

This file was deleted.

65 changes: 0 additions & 65 deletions config/files/shared/bin/studio-custom-jackd

This file was deleted.

45 changes: 0 additions & 45 deletions config/files/shared/bin/studio-toggle-jack

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
#!/usr/bin/env -S nu

$env.DBX_SUDO_PROGRAM = "pkexec"
let DISTROBOX_DOWNLOAD_URL = "https://raw.githubusercontent.com/89luca89/distrobox/main/install"

let valid_package_managers = ["apt", "brew", "nix", "dnf", "yum", "paru", "pacman"]
let distroboxes = [
const DISTROBOX_DOWNLOAD_URL = "https://raw.githubusercontent.com/89luca89/distrobox/main/install"
const valid_package_managers = ["apt", "brew", "nix", "dnf", "yum", "paru", "pacman"]
const distroboxes = [
["aliases","name", "image"];
["ubuntu", "ubuntubox", "ghcr.io/ublue-os/ubuntu-toolbox:latest"]
["arch", "archbox", "ghcr.io/ublue-os/arch-distrobox:latest"]
["fedora", "fedorabox", "ghcr.io/ublue-os/fedora-toolbox"]
]

# Export selected packages from selected subsystem to the host system
def "main export" [
export def "main add export" [
--export (-e): string # Path where packages will be exported to (default: ~/.local/bin),
box_or_subsystem: string,
...packages: string
] {

mut exportPath = ""
if ($export == null) or ($export == "") {
$exportPath = $"($env.HOME)/.local/bin"
Expand All @@ -34,12 +31,12 @@ def "main export" [
}

# List all available commands and subsystems
def "main list" [] {
export def "main add list" [] {
echo $"Valid package managers:\n($valid_package_managers | table)\nSubsystems \(Distroboxes\):\n($distroboxes| table)"
}

# Add a package to your Atomic Studio system by using package subsystems or host-based package managers.
def "main" [
export def "main add" [
--yes (-y) # Skip all confirmation prompts,
--export (-e): string # Path where packages will be exported to (default: ~/.local/bin)
--manager (-m): string # Package manager that will be used (default: brew)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env -S nu

let DISTROBOX_DOWNLOAD_URL = "https://raw.githubusercontent.com/89luca89/distrobox/main/install"
let INSTALLATION_BOX = "davincibox"
let DAVINCI_IMAGE = "ghcr.io/zelikos/davincibox:latest"
const DISTROBOX_DOWNLOAD_URL = "https://raw.githubusercontent.com/89luca89/distrobox/main/install"
const INSTALLATION_BOX = "davincibox"
const DAVINCI_IMAGE = "ghcr.io/zelikos/davincibox:latest"

def user_prompt [yes: bool] {
if $yes {
Expand All @@ -17,7 +17,7 @@ def fancy_prompt_message [package_manager: string] {
}

# Delete Davinci Resolve in a from a distrobox
def "main remove" [
export def "main davinci remove" [
--yes (-y) # Skip all confirmation prompts,
--box_name: string # Name of the distrobox where davinci-installer will be run from
] {
Expand All @@ -43,7 +43,7 @@ def "main remove" [
}

# Install Davinci Resolve in a compatible distrobox
def "main" [
export def "main davinci" [
--yes (-y) # Skip all confirmation prompts,
--box_name: string # Name of the distrobox where davinci-installer will be run from
script_path: string # The script that will be run to install Davinci Resolve
Expand Down
119 changes: 119 additions & 0 deletions config/files/shared/libexec/atomic-studio-cli/jackd.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env -S nu

const SYSTEM_JACKD_SCRIPT_PATH = "/usr/libexec/studio-jackd-default"

const DEFAULT_SCRIPT = "#!/usr/bin/env -S nu
jack_control start
jack_control ds alsa
jack_control dps rate 48000
jack_control dps nperiods 2
jack_control dps period 64
sleep 5sec
a2j_control --ehw
a2j_control --start
sleep 5sec
qjackctl &"


def user_prompt [yes: bool] {
let user_response = input "[Y/n]> "
return (($user_response =~ "(?i)yes") or ($user_response =~ "(?i)y"))
}

# Toggle Jackd only mode
export def "main jackd toggle" [
--yes (-y) # Skip confirmation prompts
] {
let CURRENT_IMAGE = (rpm-ostree status -b --json | jq -r '.deployments[0]."container-image-reference"')

if ($CURRENT_IMAGE | grep -q "/var/ublue-os/image") {
echo "Before we can switch to the Jack image,the current system needs an update. Do you wish to update?"

if (not (user_prompt $yes)) {
exit 0
}

studio update
exit 0
}

mut CURRENT_STATE = "disabled"
if ($CURRENT_IMAGE | grep -q "jack") {
$CURRENT_STATE = "enabled"
}

echo "Jack-only mode is currently ${CURRENT_STATE}"
echo "Enable or Disable jack-only mode"
let OPTION = (gum choose Enable Disable)

if "$OPTION" == "Enable" {
if "$CURRENT_STATE" == "enabled" {
echo "You are already on a jack image"
} else {
echo "Rebasing to a pipewire image"
let base_image_name = ($CURRENT_IMAGE | sed 's|^ostree-image-signed:docker://ghcr.io/.*/||')
rpm-ostree rebase $"ostree-image-signed:docker://($base_image_name)-jack:latest"
}
} else if "$OPTION" == "Disable" {
if "$CURRENT_STATE" == "enabled" {
echo "Rebasing to a pipewire image"
rpm-ostree rebase ($CURRENT_IMAGE | str replace --all "-jack" "")
} else {
echo "You are currently not on a pipewire image"
}
}
}

# Do not use the users jackd script instead of the predefined system script
export def "main jackd disable-user" [] {
let USER_JACKD_ENABLED = $"($env.HOME)/.config/atomic-studio/jack/user_custom_jackd"
if not ($USER_JACKD_ENABLED | path exists) {
echo "Custom JackD script for the user not enabled"
exit 0
}

rm $USER_JACKD_ENABLED
echo "Sucessfully disabled custom user jack script"
}

# Use the users jackd script instead of the predefined system script
export def "main jackd enable-user" [] {
let DEFAULT_CUSTOM_SCRIPT_PATH = $"($env.HOME)/.config/atomic-studio/jack/custom-jackd.nu"
let USER_JACKD_ENABLED = $"($env.HOME)/.config/atomic-studio/jack/user_custom_jackd"
if ($USER_JACKD_ENABLED | path exists) {
echo "Custom JackD script for the user already is enabled"
exit 0
}

mkdir ($DEFAULT_CUSTOM_SCRIPT_PATH | path dirname)
touch $USER_JACKD_ENABLED
$DEFAULT_SCRIPT | save -f $DEFAULT_CUSTOM_SCRIPT_PATH
echo "Sucessfully enabled custom user jack script"
}

# Run jackd with a specific script
export def "main jackd" [
--entrypoint (-e): string # Entrypoint script for running jackd (default: ~/.config/atomic-studio/jack/custom-jackd.nu)
...args # Arguments that will be passed to the script
] {
let DEFAULT_CUSTOM_SCRIPT_PATH = $"($env.HOME)/.config/atomic-studio/jack/custom-jackd.nu"
let USER_JACKD_ENABLED = $"($env.HOME)/.config/atomic-studio/jack/user_custom_jackd"

mut entrypoint_path = ""
if $entrypoint == null {
# There is something very... wrong with this but it seems to work?
if ($USER_JACKD_ENABLED | path exists) {
$entrypoint_path = $SYSTEM_JACKD_SCRIPT_PATH
} else {
$entrypoint_path = $DEFAULT_CUSTOM_SCRIPT_PATH
}
}

if not ($entrypoint_path | path exists) {
mkdir ($entrypoint_path | path dirname)
$DEFAULT_SCRIPT | save -f $entrypoint_path
chmod +x $entrypoint_path
}

run-external $entrypoint_path ...$args
}
8 changes: 8 additions & 0 deletions config/files/shared/libexec/atomic-studio-cli/mod.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export use add.nu *
export use jackd.nu *
export use davinci.nu *
export use motd.nu *
export use reporter.nu *
export use speaker-test.nu *
export use update.nu *
export use pwjack.nu *
Loading

0 comments on commit 8386ea0

Please sign in to comment.