Skip to content

Commit

Permalink
Merge branch 'main' into auto-cpufreq
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevithakannan2 committed Nov 8, 2024
2 parents c62e53f + f5f3824 commit 3fb9cce
Show file tree
Hide file tree
Showing 83 changed files with 1,324 additions and 191 deletions.
9 changes: 1 addition & 8 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,4 @@ updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
ignore:
- dependency-name: "actions/stale"
versions: '>= 9'
- dependency-name: "actions/setup-python"
versions: '> 4'
- dependency-name: "crossterm"
versions: '> 0.27.0'
interval: "weekly"
3 changes: 2 additions & 1 deletion .shellcheckrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
external-sources=true
source=core/tabs/common-script.sh
source=core/tabs/common-script.sh
source=core/tabs/common-service-script.sh
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ license = "MIT"
version = "24.9.28"
edition = "2021"

[workspace.dependencies]
ego-tree = "0.6.2"

[workspace]
members = ["tui", "core", "xtask"]
default-members = ["tui", "core"]
Expand Down
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ curl -fsSL https://christitus.com/linux | sh
```bash
curl -fsSL https://christitus.com/linuxdev | sh
```
<details>
<summary>CLI arguments</summary>

Linutil supports various command-line arguments to customize its behavior. Here are some common arguments you can use:

- `-t, --theme <THEME>` : Set the theme to use in the application [default: default] [possible values: default, compatible].
- `--override-validation` : Show all available options, disregarding compatibility checks (UNSAFE).
- `-h, --help` : Print help.

For more detailed usage, run:

```bash
curl -fsSL https://christitus.com/linux | sh -s -- --help
```

```bash
linutil --help
```
</details>

## ⬇️ Installation

Linutil is also available as a package in various repositories:
Expand Down Expand Up @@ -58,7 +78,15 @@ paru -S linutil
Replace `paru` with your preferred helper and `linutil` with your preferred package.

</details>
<details>
<summary>OpenSUSE</summary>

Linutil can be installed on OpenSUSE with:
```bash
sudo zypper install linutil
```

</details>
<details>
<summary>Cargo</summary>

Expand All @@ -72,6 +100,28 @@ Note that crates installed using `cargo install` require manual updating with `c

</details>

## Configuration

Linutil supports configuration through a TOML config file. Path to the file can be specified with `--config` (or `-c`).

Available options:
- `auto_execute` - a list of commands to execute automatically (can be combined with `--skip-confirmation`)

Example config:
```toml
# example_config.toml

auto_execute = [
"Fastfetch",
"Alacritty",
"Kitty"
]
```

```bash
linutil --config /path/to/example_config.toml
```

## 💖 Support

If you find Linutil helpful, please consider giving it a ⭐️ to show your support!
Expand Down
8 changes: 2 additions & 6 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ repository = "https://github.com/ChrisTitusTech/linutil/tree/main/core"
edition = "2021"
version.workspace = true
license.workspace = true
include = [
"src/*.rs",
"Cargo.toml",
"tabs/**",
]
include = ["src/*.rs", "Cargo.toml", "tabs/**"]

[dependencies]
include_dir = "0.7.4"
temp-dir = "0.1.14"
serde = { version = "1.0.205", features = ["derive"], default-features = false }
toml = { version = "0.8.19", features = ["parse"], default-features = false }
which = "6.0.3"
ego-tree = { workspace = true }
ego-tree = "0.9.0"
28 changes: 28 additions & 0 deletions core/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use serde::Deserialize;
use std::path::Path;
use std::process;

#[derive(Deserialize)]
pub struct Config {
pub auto_execute: Vec<String>,
}

impl Config {
pub fn from_file(path: &Path) -> Self {
let content = match std::fs::read_to_string(path) {
Ok(content) => content,
Err(e) => {
eprintln!("Failed to read config file {}: {}", path.display(), e);
process::exit(1);
}
};

match toml::from_str(&content) {
Ok(config) => config,
Err(e) => {
eprintln!("Failed to parse config file: {}", e);
process::exit(1);
}
}
}
}
39 changes: 33 additions & 6 deletions core/src/inner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{
fs::File,
io::{BufRead, BufReader, Read},
ops::{Deref, DerefMut},
os::unix::fs::PermissionsExt,
path::{Path, PathBuf},
rc::Rc,
Expand All @@ -14,8 +15,34 @@ use temp_dir::TempDir;

const TAB_DATA: Dir = include_dir!("$CARGO_MANIFEST_DIR/tabs");

pub fn get_tabs(validate: bool) -> (TempDir, Vec<Tab>) {
let (temp_dir, tab_files) = TabList::get_tabs();
// Allow the unused TempDir to be stored for later destructor call
#[allow(dead_code)]
pub struct TabList(pub Vec<Tab>, TempDir);

// Implement deref to allow Vec<Tab> methods to be called on TabList
impl Deref for TabList {
type Target = Vec<Tab>;

fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for TabList {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl IntoIterator for TabList {
type Item = Tab;
type IntoIter = std::vec::IntoIter<Self::Item>;

fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}

pub fn get_tabs(validate: bool) -> TabList {
let (temp_dir, tab_files) = TabDirectories::get_tabs();

let tabs: Vec<_> = tab_files
.into_iter()
Expand Down Expand Up @@ -50,11 +77,11 @@ pub fn get_tabs(validate: bool) -> (TempDir, Vec<Tab>) {
if tabs.is_empty() {
panic!("No tabs found");
}
(temp_dir, tabs)
TabList(tabs, temp_dir)
}

#[derive(Deserialize)]
struct TabList {
struct TabDirectories {
directories: Vec<PathBuf>,
}

Expand Down Expand Up @@ -246,9 +273,9 @@ fn is_executable(path: &Path) -> bool {
.unwrap_or(false)
}

impl TabList {
impl TabDirectories {
fn get_tabs() -> (TempDir, Vec<PathBuf>) {
let temp_dir = TempDir::new().unwrap();
let temp_dir = TempDir::with_prefix("linutil_scripts").unwrap();
TAB_DATA
.extract(&temp_dir)
.expect("Failed to extract the saved directory");
Expand Down
18 changes: 17 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
mod config;
mod inner;

use std::rc::Rc;

pub use ego_tree;
use ego_tree::Tree;
use std::path::PathBuf;

pub use inner::get_tabs;
pub use config::Config;
pub use inner::{get_tabs, TabList};

#[derive(Clone, Hash, Eq, PartialEq)]
pub enum Command {
Expand Down Expand Up @@ -33,3 +36,16 @@ pub struct ListNode {
pub task_list: String,
pub multi_select: bool,
}

impl Tab {
pub fn find_command(&self, name: &str) -> Option<Rc<ListNode>> {
self.tree.root().descendants().find_map(|node| {
let value = node.value();
if value.name == name && !node.has_children() {
Some(value.clone())
} else {
None
}
})
}
}
3 changes: 3 additions & 0 deletions core/tabs/applications-setup/Developer-tools/meld-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ installMeld() {
apt-get|nala)
"$ESCALATION_TOOL" "$PACKAGER" -y install meld
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add meld
;;
*)
checkFlatpak
flatpak install -y flathub org.gnome.meld
Expand Down
3 changes: 3 additions & 0 deletions core/tabs/applications-setup/Developer-tools/neovim-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ installNeovim() {
dnf|zypper)
"$ESCALATION_TOOL" "$PACKAGER" install -y neovim ripgrep fzf python3-virtualenv luarocks golang ShellCheck git
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add neovim ripgrep fzf py3-virtualenv luarocks go shellcheck git
;;
*)
printf "%b\n" "${RED}Unsupported package manager: ""$PACKAGER""${RC}"
exit 1
Expand Down
6 changes: 5 additions & 1 deletion core/tabs/applications-setup/Developer-tools/vscode-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
. ../../common-script.sh

installVsCode() {
if ! command_exists code; then
if ! command_exists com.visualstudio.code && ! command_exists code; then
printf "%b\n" "${YELLOW}Installing VS Code..${RC}."
case "$PACKAGER" in
apt-get|nala)
Expand All @@ -28,6 +28,10 @@ installVsCode() {
printf "%b\n" '[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc' | "$ESCALATION_TOOL" tee /etc/yum.repos.d/vscode.repo > /dev/null
"$ESCALATION_TOOL" "$PACKAGER" install -y code
;;
apk)
checkFlatpak
flatpak install -y flathub com.visualstudio.code
;;
*)
printf "%b\n" "${RED}Unsupported package manager: ""$PACKAGER""${RC}"
exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
. ../../common-script.sh

installVsCodium() {
if ! command_exists codium; then
if ! command_exists com.vscodium.codium && ! command_exists codium; then
printf "%b\n" "${YELLOW}Installing VS Codium...${RC}"
case "$PACKAGER" in
apt-get|nala)
Expand All @@ -26,6 +26,10 @@ installVsCodium() {
printf "%b\n" "[gitlab.com_paulcarroty_vscodium_repo]\nname=download.vscodium.com\nbaseurl=https://download.vscodium.com/rpms/\nenabled=1\ngpgcheck=1\nrepo_gpgcheck=1\ngpgkey=https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/-/raw/master/pub.gpg\nmetadata_expire=1h" | "$ESCALATION_TOOL" tee -a /etc/yum.repos.d/vscodium.repo
"$ESCALATION_TOOL" "$PACKAGER" install -y codium
;;
apk)
checkFlatpak
flatpak install -y flathub com.vscodium.codium
;;
*)
printf "%b\n" "${RED}Unsupported package manager: ""$PACKAGER""${RC}"
exit 1
Expand Down
3 changes: 3 additions & 0 deletions core/tabs/applications-setup/alacritty-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ installAlacritty() {
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm alacritty
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add alacritty
;;
*)
"$ESCALATION_TOOL" "$PACKAGER" install -y alacritty
;;
Expand Down
3 changes: 3 additions & 0 deletions core/tabs/applications-setup/android-debloat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ install_adb() {
dnf|zypper)
"$ESCALATION_TOOL" "$PACKAGER" install -y android-tools
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add android-tools
;;
*)
printf "%b\n" "${RED}Unsupported package manager: "$PACKAGER"${RC}"
exit 1
Expand Down
6 changes: 5 additions & 1 deletion core/tabs/applications-setup/browsers/brave.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
. ../../common-script.sh

installBrave() {
if ! command_exists brave; then
if ! command_exists com.brave.Browser && ! command_exists brave; then
printf "%b\n" "${YELLOW}Installing Brave...${RC}"
case "$PACKAGER" in
apt-get|nala)
Expand All @@ -29,6 +29,10 @@ installBrave() {
"$ESCALATION_TOOL" rpm --import https://brave-browser-rpm-release.s3.brave.com/brave-core.asc
"$ESCALATION_TOOL" "$PACKAGER" install -y brave-browser
;;
apk)
checkFlatpak
flatpak install -y flathub com.brave.Browser
;;
*)
printf "%b\n" "${RED}Unsupported package manager: ""$PACKAGER""${RC}"
exit 1
Expand Down
3 changes: 3 additions & 0 deletions core/tabs/applications-setup/browsers/chromium.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ if ! command_exists chromium; then
pacman)
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm chromium
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add chromium
;;
*)
"$ESCALATION_TOOL" "$PACKAGER" install -y chromium
;;
Expand Down
3 changes: 3 additions & 0 deletions core/tabs/applications-setup/browsers/firefox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ installFirefox() {
dnf)
"$ESCALATION_TOOL" "$PACKAGER" install -y firefox
;;
apk)
"$ESCALATION_TOOL" "$PACKAGER" add firefox
;;
*)
printf "%b\n" "${RED}Unsupported package manager: ""$PACKAGER""${RC}"
exit 1
Expand Down
Loading

0 comments on commit 3fb9cce

Please sign in to comment.