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

Commit

Permalink
fix: many studio CLI UX issues! #56
Browse files Browse the repository at this point in the history
  • Loading branch information
tulilirockz committed Mar 15, 2024
1 parent b6fac06 commit 66a1c28
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 104 deletions.
59 changes: 0 additions & 59 deletions config/files/shared/libexec/atomic-studio-cli/davinci.nu
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,5 @@ use lib/user_interaction.nu [fancy_prompt_message, user_prompt]
use lib/generic_install.nu [generic_script_installation]
use lib/distrobox.nu [create_container_optional]

const INSTALLATION_BOX = "davincibox"
const DAVINCI_IMAGE = "ghcr.io/zelikos/davincibox:latest"

# Delete Davinci Resolve in a from a distrobox
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
--delete-box # Also delete container
] {
if (which distrobox | length) == 0 {
fancy_prompt_message "Distrobox"
if not (user_prompt $yes) {
exit 0
}
generic_script_installation $yes "Distrobox" (distrobox_installer)
}

mut install_box = ""
if $box_name == null {
$install_box = $INSTALLATION_BOX
}

try { distrobox ls | grep $install_box } catch {
echo "The selected box ($install_box) is not created yet."
exit 1
}

distrobox enter $install_box '--' sh -c "add-davinci-launcher remove"
if $delete_box != null {
distrobox rm $install_box
}
}

# Install Davinci Resolve in a compatible distrobox
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
] {
if (which distrobox | length) == 0 {
fancy_prompt_message "Distrobox"
if not (user_prompt $yes) {
exit 0
}
generic_script_installation $yes "Distrobox" (distrobox_installer)
}

mut install_box = ""
if $box_name == null {
$install_box = $INSTALLATION_BOX
}
let box_name = $install_box

create_container_optional $yes {name: $box_name, description: "Davinci container", image: $DAVINCI_IMAGE}

mkdir $"($env.HOME)/.cache/davincibox"
cp -f $script_path $"($env.HOME)/.cache/davincibox/dresolve.run"
distrobox enter $box_name -- bash -c $"pushd ($env.HOME)/.cache/davincibox && ./dresolve.run --appimage-extract && popd"
distrobox enter $box_name -- sh -c $"setup-davinci ($env.HOME)/.cache/davincibox/squashfs-root/AppRun distrobox && add-davinci-launcher distrobox"
rm -rf $"($env.HOME)/.cache/davincibox"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ export def distrobox_install [
manager: record<box_distro: string, installer_command: string>
] {
if (which distrobox | length) == 0 {
fancy_prompt_message "Distrobox"
if not (user_prompt $package_data.no_confirm) {
exit 0
}
generic_script_installation $package_data.no_confirm "distrobox" (distrobox_installer)
exit 0
}

let box_name: string = ($DISTROBOXES_META | where aliases == $manager.box_distro | get name).0
Expand Down
2 changes: 1 addition & 1 deletion config/files/shared/libexec/atomic-studio-cli/manager.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use lib/user_interaction.nu [user_prompt]
use lib/distrobox.nu [DISTROBOXES_META]
use lib/manager_lib.nu [brew_install, nix_install, distrobox_install, pipx_install, brew_uninstall, nix_uninstall, distrobox_uninstall, pipx_uninstall]
use lib/manager_installers.nu [brew_install, nix_install, distrobox_install, pipx_install, brew_uninstall, nix_uninstall, distrobox_uninstall, pipx_uninstall]

# Available package managers: ["apt", "brew", "nix", "dnf", "yum", "paru", "pacman", "pipx"]
export def "main manager" [] {
Expand Down
1 change: 0 additions & 1 deletion config/files/shared/libexec/atomic-studio-cli/mod.nu
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export use manager.nu *
export use davinci.nu *
export use motd.nu *
export use reporter.nu *
export use speaker-test.nu *
Expand Down
37 changes: 24 additions & 13 deletions config/files/shared/libexec/atomic-studio-cli/motd.nu
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,24 @@ def replace_format [

# Turn MOTD off
export def "main motd off" [] {
let MOTD_DISABLED_FILE = $"($env.HOME)/.config/atomic-studio/motd_enabled"
rm $MOTD_DISABLED_FILE
let MOTD_DISABLED_FILE = $"($env.HOME)/.config/atomic-studio/motd_disabled"
if not ($MOTD_DISABLED_FILE | path exists) {
echo "MOTD is already disabled"
exit 0
}
mkdir ($MOTD_DISABLED_FILE | path dirname)
touch $MOTD_DISABLED_FILE
echo "Disabled MOTD for the current user"
}

# Turn MOTD on
export def "main motd on" [] {
let MOTD_DISABLED_FILE = $"($env.HOME)/.config/atomic-studio/motd_enabled"
touch $MOTD_DISABLED_FILE
let MOTD_DISABLED_FILE = $"($env.HOME)/.config/atomic-studio/motd_disabled"
if not ($MOTD_DISABLED_FILE | path exists) {
echo "MOTD is already enabled"
exit 0
}
rm $MOTD_DISABLED_FILE
echo "Enabled MOTD for the current user"
}

Expand All @@ -54,17 +63,19 @@ export def "main motd" [
exit 0
}

mut TEMPLATE_PATH = $template_path
if $template_path == null {
$TEMPLATE_PATH = $STUDIO_TEMPLATE_PATH
mut TEMPLATE_PATH = $STUDIO_TEMPLATE_PATH
if $template_path != null {
$TEMPLATE_PATH = $template_path
}
mut MOTD_PATH = $motd_path
if $motd_path == null {
$MOTD_PATH = "/usr/share/ublue-os/atomic-studio/motd/tips"

mut MOTD_PATH = "/usr/share/ublue-os/atomic-studio/motd/tips"
if $motd_path != null {
$MOTD_PATH = $motd_path
}
mut IMAGE_INFO_PATH = $image_info_path
if $image_info_path == null {
$IMAGE_INFO_PATH = "/usr/share/ublue-os/image-info.json"

mut IMAGE_INFO_PATH = "/usr/share/ublue-os/image-info.json"
if $image_info_path != null {
$IMAGE_INFO_PATH = $image_info_path
}

let CURRENT_TIP_FILE = (ls $MOTD_PATH | where { |e| ($e.type == "file") and ($e.name | str ends-with md) } | shuffle | get 0.name)
Expand Down
14 changes: 6 additions & 8 deletions config/files/shared/libexec/atomic-studio-cli/pw.nu
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export def "main pw reset quantum-buffersize" [] {
}

# Set specific buffersize for PIPEWIRE_QUANTUM variable (fixes ardour and carla crashes)
export def "main pw set quantum-buffersize" [--buffersize (-b): int] {
export def "main pw set quantum-buffersize" [buffersize: int] {
mut is_valid_thing: bool = false
mut iter = 0
let max_iter = ($VALID_BFSIZES | length)
Expand All @@ -38,6 +38,7 @@ export def "main pw set quantum-buffersize" [--buffersize (-b): int] {
if VALID_BFSIZES.$iter == $buffersize {
$is_valid_thing = true
}
$iter = $iter + 1
}

if not is_valid_thing {
Expand All @@ -53,7 +54,6 @@ export def "main pw set quantum-buffersize" [--buffersize (-b): int] {

# Edit your own custom configuration for pipewire
export def "main pw set config" [
--system (-s) # Select system configurations to override
--user (-u) # Select user configs
] {
let pipewire_config_path = $"($env.HOME)/.config/pipewire"
Expand All @@ -62,16 +62,14 @@ export def "main pw set config" [
mkdir $pipewire_config_path

mut target_fpath = ""
if $system != null {
$target_fpath = $pipewire_sys_path
}
$target_fpath = $pipewire_sys_path
if $user != null {
$target_fpath = $pipewire_config_path
}

let selected_config_file = (gum file $target_fpath)

if $system != null {
if $user == null {
cp $selected_config_file $pipewire_config_path
}
mut editor = "nano"
Expand All @@ -87,7 +85,7 @@ export def "main pw enable realtime" [] {
rpm-ostree kargs --append-if-missing="threadirqs"

for $group in $REALTIME_GROUPS {
usermod -a -G $group $env.USER
pkexec usermod -a -G $group $env.USER
}
echo "Reboot for changes to take effect."
}
Expand All @@ -98,7 +96,7 @@ export def "main pw disable realtime" [] {
rpm-ostree kargs --delete-if-present="threadirqs"

for $group in $REALTIME_GROUPS {
usermod -R $group $env.USER
pkexec usermod -R $group $env.USER
}
echo "Reboot for changes to take effect."
}
Expand Down
7 changes: 3 additions & 4 deletions config/files/shared/libexec/atomic-studio-cli/reporter.nu
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export def "main reporter" [
$method_command = match $method {
termbin => "nc termbin.com 9999",
fpaste => "fpaste"
loopback => "echo $in",
loopback | loop | lp => "echo $in",
}
if $method == null {
$method_command = "fpaste"
Expand All @@ -40,13 +40,12 @@ export def "main reporter" [

$fetch | each { |fetch_arg|
table_commands ...(match $fetch_arg {
hw => { ["lscpu" "lsmem" "lsblk" "mount"] },
audio => { ["pactl info", "pw-dump"] },
packages => { ["rpm -qa" "rpm-ostree status -v"] },
distrobox => { ["podman images" "distrobox ls" "podman ps -a"] },
systemd => { ["systemctl status" "systemctl status --user"] },
env => { ["$env"] }
_ => [],
env => { ["$env"] },
_ => { ["lscpu" "lsmem" "lsblk" "mount"] }
})
} | table -e --theme basic | nu --stdin -c $"($method_command)"
}
Loading

0 comments on commit 66a1c28

Please sign in to comment.