Compare commits

...

8 Commits

Author SHA1 Message Date
JEEVITHA KANNAN K S
d0bc7197bc
Merge 99c7f984b4 into e3688e9b3d 2024-10-25 16:04:53 +02:00
Adam Perkowski
e3688e9b3d
fix+refact(system-cleanup) (#856)
* fix(system-cleanup): some issues

* new packager quotes
2024-10-24 14:59:23 -05:00
Adam Perkowski
51631a16cb
feat: desktop entry & manpage installation through linutil-installer.sh (#802) 2024-10-24 14:55:56 -05:00
Adam Perkowski
d39ffad527
📖 fix(docs): newlines (#796) 2024-10-24 14:50:27 -05:00
Adam Perkowski
c0982a787f
📖 add auto docs generation instructions to the Contributing Guidelines (#788)
* 📖 add auto docs generation instructions to the Contributing Guidelines

* Commit Contributing Guidelines

---------

Co-authored-by: adamperkowski <adamperkowski@users.noreply.github.com>
2024-10-24 14:45:37 -05:00
Adam Perkowski
4f7de594a6
🔍️ exiting search with Ctrl-C + better shortcut tips (#768) 2024-10-24 14:43:16 -05:00
Adam Perkowski
fa2f838b63
📃 fix(monitor setup): a bug with utility-functions; newlines & colors in the scripts (#713)
* fixed newlines & changed colors to keep synergy

* fixed a bug
2024-10-24 14:39:04 -05:00
JEEVITHA KANNAN K S
99c7f984b4
Fix btrfs issue 2024-10-02 11:47:37 +05:30
14 changed files with 100 additions and 62 deletions

View File

@ -16,6 +16,7 @@ cd linutil
``` ```
## 3. Make your changes ## 3. Make your changes
- **Edit the files you want to change**: Make your changes to the relevant files. - **Edit the files you want to change**: Make your changes to the relevant files.
- **Test your changes**: Run `cargo run` to test your modifications in a local environment and ensure everything works as expected. - **Test your changes**: Run `cargo run` to test your modifications in a local environment and ensure everything works as expected.
@ -60,6 +61,7 @@ cd linutil
## 11. Documentation ## 11. Documentation
- **Update the documentation**: If your change affects the functionality, please update the relevant documentation files to reflect this. - **Update the documentation**: If your change affects the functionality, please update the relevant documentation files to reflect this.
- **Automatic generation**: If you decide to add functionality through a new shell script, make sure to fill out all fields in `tab_data.toml` and run `cargo xtask docgen`.
## 12. License ## 12. License

View File

@ -22,7 +22,7 @@ jobs:
- name: Copy Contributing Guidelines - name: Copy Contributing Guidelines
run: | run: |
echo "<!-- THIS FILE IS GENERATED AUTOMATICALLY. EDIT .github/CONTRIBUTING.md -->\n\n$(cat .github/CONTRIBUTING.md)" > 'docs/contributing.md' echo -e "<!-- THIS FILE IS GENERATED AUTOMATICALLY. EDIT .github/CONTRIBUTING.md -->\n\n$(cat .github/CONTRIBUTING.md)" > 'docs/contributing.md'
- uses: stefanzweifel/git-auto-commit-action@v5 - uses: stefanzweifel/git-auto-commit-action@v5
with: with:

View File

@ -35,10 +35,10 @@ installLinutil() {
printf "%b\n" "${YELLOW}Installing rustup...${RC}" printf "%b\n" "${YELLOW}Installing rustup...${RC}"
case "$PACKAGER" in case "$PACKAGER" in
pacman) pacman)
"$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm rustup "$ESCALATION_TOOL" "$PACKAGER" -S --needed --noconfirm curl rustup man-db
;; ;;
dnf) dnf)
"$ESCALATION_TOOL" "$PACKAGER" install -y rustup "$ESCALATION_TOOL" "$PACKAGER" install -y curl rustup man-pages man-db man
;; ;;
zypper) zypper)
"$ESCALATION_TOOL" "$PACKAGER" install -n curl gcc make "$ESCALATION_TOOL" "$PACKAGER" install -n curl gcc make
@ -54,12 +54,23 @@ installLinutil() {
rustup default stable rustup default stable
cargo install --force linutil_tui cargo install --force linutil_tui
printf "%b\n" "${GREEN}Installed successfully.${RC}" printf "%b\n" "${GREEN}Installed successfully.${RC}"
installExtra
;; ;;
*) printf "%b\n" "${RED}Linutil not installed.${RC}" ;; *) printf "%b\n" "${RED}Linutil not installed.${RC}" ;;
esac esac
esac esac
} }
installExtra() {
printf "%b\n" "${YELLOW}Installing the manpage...${RC}"
"$ESCALATION_TOOL" mkdir -p /usr/share/man/man1
curl 'https://raw.githubusercontent.com/ChrisTitusTech/linutil/refs/heads/main/man/linutil.1' | "$ESCALATION_TOOL" tee '/usr/share/man/man1/linutil.1' > /dev/null
printf "%b\n" "${YELLOW}Creating a Desktop Entry...${RC}"
"$ESCALATION_TOOL" mkdir -p /usr/share/applications
curl 'https://raw.githubusercontent.com/ChrisTitusTech/linutil/refs/heads/main/linutil.desktop' | "$ESCALATION_TOOL" tee /usr/share/applications/linutil.desktop > /dev/null
printf "%b\n" "${GREEN}Done.${RC}"
}
checkEnv checkEnv
checkEscalationTool checkEscalationTool
checkAURHelper checkAURHelper

View File

@ -130,7 +130,7 @@ echo -ne "
██║ ██║██║ ██║╚██████╗██║ ██║ ██║ ██║ ██║ ╚██████╔╝███████║ ██║ ██║██║ ██║╚██████╗██║ ██║ ██║ ██║ ██║ ╚██████╔╝███████║
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝
------------------------------------------------------------------------ ------------------------------------------------------------------------
Please select presetup settings for your system Please select presetup settings for your system
------------------------------------------------------------------------ ------------------------------------------------------------------------
" "
} }
@ -146,7 +146,7 @@ filesystem () {
case $? in case $? in
0) export FS=btrfs;; 0) export FS=btrfs;;
1) export FS=ext4;; 1) export FS=ext4;;
2) 2)
set_password "LUKS_PASSWORD" set_password "LUKS_PASSWORD"
export FS=luks export FS=luks
;; ;;
@ -155,14 +155,14 @@ filesystem () {
esac esac
} }
# @description Detects and sets timezone. # @description Detects and sets timezone.
timezone () { timezone () {
# Added this from arch wiki https://wiki.archlinux.org/title/System_time # Added this from arch wiki https://wiki.archlinux.org/title/System_time
time_zone="$(curl --fail https://ipapi.co/timezone)" time_zone="$(curl --fail https://ipapi.co/timezone)"
echo -ne " echo -ne "
System detected your timezone to be '$time_zone' \n" System detected your timezone to be '$time_zone' \n"
echo -ne "Is this correct? echo -ne "Is this correct?
" "
options=("Yes" "No") options=("Yes" "No")
select_option "${options[@]}" select_option "${options[@]}"
@ -171,14 +171,14 @@ timezone () {
echo "${time_zone} set as timezone" echo "${time_zone} set as timezone"
export TIMEZONE=$time_zone;; export TIMEZONE=$time_zone;;
n|N|no|NO|No) n|N|no|NO|No)
echo "Please enter your desired timezone e.g. Europe/London :" echo "Please enter your desired timezone e.g. Europe/London :"
read -r new_timezone read -r new_timezone
echo "${new_timezone} set as timezone" echo "${new_timezone} set as timezone"
export TIMEZONE=$new_timezone;; export TIMEZONE=$new_timezone;;
*) echo "Wrong option. Try again";timezone;; *) echo "Wrong option. Try again";timezone;;
esac esac
} }
# @description Set user's keyboard mapping. # @description Set user's keyboard mapping.
keymap () { keymap () {
echo -ne " echo -ne "
Please select key board layout from this list" Please select key board layout from this list"
@ -236,18 +236,18 @@ echo -ne "
drivessd drivessd
} }
# @description Gather username and password to be used for installation. # @description Gather username and password to be used for installation.
userinfo () { userinfo () {
# Loop through user input until the user gives a valid username # Loop through user input until the user gives a valid username
while true while true
do do
read -r -p "Please enter username: " username read -r -p "Please enter username: " username
if [[ "${username,,}" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]] if [[ "${username,,}" =~ ^[a-z_]([a-z0-9_-]{0,31}|[a-z0-9_-]{0,30}\$)$ ]]
then then
break break
fi fi
echo "Incorrect username." echo "Incorrect username."
done done
export USERNAME=$username export USERNAME=$username
while true while true
@ -264,22 +264,22 @@ userinfo () {
done done
export PASSWORD=$PASSWORD1 export PASSWORD=$PASSWORD1
# Loop through user input until the user gives a valid hostname, but allow the user to force save # Loop through user input until the user gives a valid hostname, but allow the user to force save
while true while true
do do
read -r -p "Please name your machine: " name_of_machine read -r -p "Please name your machine: " name_of_machine
# hostname regex (!!couldn't find spec for computer name!!) # hostname regex (!!couldn't find spec for computer name!!)
if [[ "${name_of_machine,,}" =~ ^[a-z][a-z0-9_.-]{0,62}[a-z0-9]$ ]] if [[ "${name_of_machine,,}" =~ ^[a-z][a-z0-9_.-]{0,62}[a-z0-9]$ ]]
then then
break break
fi fi
# if validation fails allow the user to force saving of the hostname # if validation fails allow the user to force saving of the hostname
read -r -p "Hostname doesn't seem correct. Do you still want to save it? (y/n)" force read -r -p "Hostname doesn't seem correct. Do you still want to save it? (y/n)" force
if [[ "${force,,}" = "y" ]] if [[ "${force,,}" = "y" ]]
then then
break break
fi fi
done done
export NAME_OF_MACHINE=$name_of_machine export NAME_OF_MACHINE=$name_of_machine
} }
@ -351,7 +351,7 @@ echo -ne "
Creating Filesystems Creating Filesystems
------------------------------------------------------------------------- -------------------------------------------------------------------------
" "
# @description Creates the btrfs subvolumes. # @description Creates the btrfs subvolumes.
createsubvolumes () { createsubvolumes () {
btrfs subvolume create /mnt/@ btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home btrfs subvolume create /mnt/@home
@ -362,11 +362,11 @@ mountallsubvol () {
mount -o "${MOUNT_OPTIONS}",subvol=@home "${partition3}" /mnt/home mount -o "${MOUNT_OPTIONS}",subvol=@home "${partition3}" /mnt/home
} }
# @description BTRFS subvolulme creation and mounting. # @description BTRFS subvolulme creation and mounting.
subvolumesetup () { subvolumesetup () {
# create nonroot subvolumes # create nonroot subvolumes
createsubvolumes createsubvolumes
# unmount root to remount with subvolume # unmount root to remount with subvolume
umount /mnt umount /mnt
# mount @ subvolume # mount @ subvolume
mount -o "${MOUNT_OPTIONS}",subvol=@ "${partition3}" /mnt mount -o "${MOUNT_OPTIONS}",subvol=@ "${partition3}" /mnt
@ -386,33 +386,36 @@ fi
if [[ "${FS}" == "btrfs" ]]; then if [[ "${FS}" == "btrfs" ]]; then
mkfs.vfat -F32 -n "EFIBOOT" "${partition2}" mkfs.vfat -F32 -n "EFIBOOT" "${partition2}"
mkfs.btrfs -L ROOT "${partition3}" -f mkfs.btrfs -f "${partition3}"
mount -t btrfs "${partition3}" /mnt mount -t btrfs "${partition3}" /mnt
subvolumesetup subvolumesetup
elif [[ "${FS}" == "ext4" ]]; then elif [[ "${FS}" == "ext4" ]]; then
mkfs.vfat -F32 -n "EFIBOOT" "${partition2}" mkfs.vfat -F32 -n "EFIBOOT" "${partition2}"
mkfs.ext4 -L ROOT "${partition3}" mkfs.ext4 "${partition3}"
mount -t ext4 "${partition3}" /mnt mount -t ext4 "${partition3}" /mnt
elif [[ "${FS}" == "luks" ]]; then elif [[ "${FS}" == "luks" ]]; then
mkfs.vfat -F32 -n "EFIBOOT" "${partition2}" mkfs.vfat -F32 "${partition2}"
# enter luks password to cryptsetup and format root partition # enter luks password to cryptsetup and format root partition
echo -n "${LUKS_PASSWORD}" | cryptsetup -y -v luksFormat "${partition3}" - echo -n "${LUKS_PASSWORD}" | cryptsetup -y -v luksFormat "${partition3}" -
# open luks container and ROOT will be place holder # open luks container and ROOT will be place holder
echo -n "${LUKS_PASSWORD}" | cryptsetup open "${partition3}" ROOT - echo -n "${LUKS_PASSWORD}" | cryptsetup open "${partition3}" ROOT -
# now format that container # now format that container
mkfs.btrfs -L ROOT "${partition3}" mkfs.btrfs "${partition3}"
# create subvolumes for btrfs # create subvolumes for btrfs
mount -t btrfs "${partition3}" /mnt mount -t btrfs "${partition3}" /mnt
subvolumesetup subvolumesetup
ENCRYPTED_PARTITION_UUID=$(blkid -s UUID -o value "${partition3}")
fi fi
BOOT_UUID=$(blkid -s UUID -o value "${partition2}")
sync sync
if ! mountpoint -q /mnt; then if ! mountpoint -q /mnt; then
echo "ERROR! Failed to mount ${partition3} to /mnt after multiple attempts." echo "ERROR! Failed to mount ${partition3} to /mnt after multiple attempts."
exit 1 exit 1
fi fi
mkdir -p /mnt/boot/efi mkdir -p /mnt/boot/efi
mount -t vfat -L EFIBOOT /mnt/boot/ mount -t vfat -U "${BOOT_UUID}" /mnt/boot/
if ! grep -qs '/mnt' /proc/mounts; then if ! grep -qs '/mnt' /proc/mounts; then
echo "Drive is not mounted can not continue" echo "Drive is not mounted can not continue"
@ -435,8 +438,8 @@ fi
echo "keyserver hkp://keyserver.ubuntu.com" >> /mnt/etc/pacman.d/gnupg/gpg.conf echo "keyserver hkp://keyserver.ubuntu.com" >> /mnt/etc/pacman.d/gnupg/gpg.conf
cp /etc/pacman.d/mirrorlist /mnt/etc/pacman.d/mirrorlist cp /etc/pacman.d/mirrorlist /mnt/etc/pacman.d/mirrorlist
genfstab -L /mnt >> /mnt/etc/fstab genfstab -U /mnt >> /mnt/etc/fstab
echo " echo "
Generated /etc/fstab: Generated /etc/fstab:
" "
cat /mnt/etc/fstab cat /mnt/etc/fstab
@ -475,14 +478,14 @@ arch-chroot /mnt /bin/bash -c "KEYMAP='${KEYMAP}' /bin/bash" <<EOF
echo -ne " echo -ne "
------------------------------------------------------------------------- -------------------------------------------------------------------------
Network Setup Network Setup
------------------------------------------------------------------------- -------------------------------------------------------------------------
" "
pacman -S --noconfirm --needed networkmanager dhclient pacman -S --noconfirm --needed networkmanager dhclient
systemctl enable --now NetworkManager systemctl enable --now NetworkManager
echo -ne " echo -ne "
------------------------------------------------------------------------- -------------------------------------------------------------------------
Setting up mirrors for optimal download Setting up mirrors for optimal download
------------------------------------------------------------------------- -------------------------------------------------------------------------
" "
pacman -S --noconfirm --needed pacman-contrib curl pacman -S --noconfirm --needed pacman-contrib curl
@ -504,7 +507,7 @@ sed -i "s/COMPRESSXZ=(xz -c -z -)/COMPRESSXZ=(xz -c -T $nc -z -)/g" /etc/makepkg
fi fi
echo -ne " echo -ne "
------------------------------------------------------------------------- -------------------------------------------------------------------------
Setup Language to US and set locale Setup Language to US and set locale
------------------------------------------------------------------------- -------------------------------------------------------------------------
" "
sed -i 's/^#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen sed -i 's/^#en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
@ -572,7 +575,7 @@ echo -ne "
------------------------------------------------------------------------- -------------------------------------------------------------------------
" "
groupadd libvirt groupadd libvirt
useradd -m -G wheel,libvirt -s /bin/bash $USERNAME useradd -m -G wheel,libvirt -s /bin/bash $USERNAME
echo "$USERNAME created, home directory created, added to wheel and libvirt group, default shell set to /bin/bash" echo "$USERNAME created, home directory created, added to wheel and libvirt group, default shell set to /bin/bash"
echo "$USERNAME:$PASSWORD" | chpasswd echo "$USERNAME:$PASSWORD" | chpasswd
echo "$USERNAME password set" echo "$USERNAME password set"

23
core/tabs/system-setup/system-cleanup.sh Normal file → Executable file
View File

@ -26,16 +26,21 @@ cleanup_system() {
"$ESCALATION_TOOL" "$PACKAGER" -Rns $(pacman -Qtdq) --noconfirm > /dev/null 2>&1 "$ESCALATION_TOOL" "$PACKAGER" -Rns $(pacman -Qtdq) --noconfirm > /dev/null 2>&1
;; ;;
*) *)
printf "%b\n" "${RED}Unsupported package manager: ""$PACKAGER""${RC}" printf "%b\n" "${RED}Unsupported package manager: ${PACKAGER}. Skipping.${RC}"
return 1
;; ;;
esac esac
} }
common_cleanup() { common_cleanup() {
"$ESCALATION_TOOL" find /var/tmp -type f -atime +5 -delete if [ -d /var/tmp ]; then
"$ESCALATION_TOOL" find /tmp -type f -atime +5 -delete "$ESCALATION_TOOL" find /var/tmp -type f -atime +5 -delete
"$ESCALATION_TOOL" find /var/log -type f -name "*.log" -exec truncate -s 0 {} \; fi
if [ -d /tmp ]; then
"$ESCALATION_TOOL" find /tmp -type f -atime +5 -delete
fi
if [ -d /var/log ]; then
"$ESCALATION_TOOL" find /var/log -type f -name "*.log" -exec truncate -s 0 {} \;
fi
"$ESCALATION_TOOL" journalctl --vacuum-time=3d "$ESCALATION_TOOL" journalctl --vacuum-time=3d
} }
@ -45,8 +50,12 @@ clean_data() {
case $clean_response in case $clean_response in
y|Y) y|Y)
printf "%b\n" "${YELLOW}Cleaning up old cache files and emptying trash...${RC}" printf "%b\n" "${YELLOW}Cleaning up old cache files and emptying trash...${RC}"
find "$HOME/.cache/" -type f -atime +5 -delete if [ -d "$HOME/.cache" ]; then
find "$HOME/.local/share/Trash" -mindepth 1 -delete find "$HOME/.cache/" -type f -atime +5 -delete
fi
if [ -d "$HOME/.local/share/Trash" ]; then
find "$HOME/.local/share/Trash" -mindepth 1 -delete
fi
printf "%b\n" "${GREEN}Cache and trash cleanup completed.${RC}" printf "%b\n" "${GREEN}Cache and trash cleanup completed.${RC}"
;; ;;
*) *)

View File

@ -13,7 +13,7 @@ change_orientation() {
printf "%b\n" "${YELLOW}=========================================${RC}" printf "%b\n" "${YELLOW}=========================================${RC}"
printf "%b\n" "${YELLOW} Change Monitor Orientation${RC}" printf "%b\n" "${YELLOW} Change Monitor Orientation${RC}"
printf "%b\n" "${YELLOW}=========================================${RC}" printf "%b\n" "${YELLOW}=========================================${RC}"
printf "%b" "${YELLOW}Choose a monitor to configure: ${RC}" printf "%b\n" "${YELLOW}Choose a monitor to configure: ${RC}"
i=1 i=1
for monitor in $monitor_array; do for monitor in $monitor_array; do
printf "%b\n" "$i. ${GREEN}$monitor${RC}" printf "%b\n" "$i. ${GREEN}$monitor${RC}"

View File

@ -13,7 +13,7 @@ disable_monitor() {
printf "%b\n" "${YELLOW}=========================================${RC}" printf "%b\n" "${YELLOW}=========================================${RC}"
printf "%b\n" "${YELLOW} Disable Monitor${RC}" printf "%b\n" "${YELLOW} Disable Monitor${RC}"
printf "%b\n" "${YELLOW}=========================================${RC}" printf "%b\n" "${YELLOW}=========================================${RC}"
printf "%b" "Choose a monitor to disable: " printf "%b\n" "Choose a monitor to disable: "
i=1 i=1
for monitor in $monitor_array; do for monitor in $monitor_array; do
printf "%b\n" "$i. ${GREEN}$monitor${RC}" printf "%b\n" "$i. ${GREEN}$monitor${RC}"

View File

@ -13,7 +13,7 @@ enable_monitor() {
printf "%b\n" "${YELLOW}=========================================${RC}" printf "%b\n" "${YELLOW}=========================================${RC}"
printf "%b\n" "${YELLOW} Enable Monitor${RC}" printf "%b\n" "${YELLOW} Enable Monitor${RC}"
printf "%b\n" "${YELLOW}=========================================${RC}" printf "%b\n" "${YELLOW}=========================================${RC}"
printf "%b" "${YELLOW}Choose a monitor to enable: ${RC}" printf "%b\n" "${YELLOW}Choose a monitor to enable: ${RC}"
i=1 i=1
for monitor in $monitor_array; do for monitor in $monitor_array; do

View File

@ -1,6 +1,6 @@
#!/bin/sh -e #!/bin/sh -e
. ./utility_functions.sh . ../utility_functions.sh
. ../../common-script.sh . ../../common-script.sh

View File

@ -13,10 +13,10 @@ manage_arrangement() {
printf "%b\n" "${YELLOW}=========================================${RC}" printf "%b\n" "${YELLOW}=========================================${RC}"
printf "%b\n" "${YELLOW} Manage Monitor Arrangement${RC}" printf "%b\n" "${YELLOW} Manage Monitor Arrangement${RC}"
printf "%b\n" "${YELLOW}=========================================${RC}" printf "%b\n" "${YELLOW}=========================================${RC}"
printf "%b" "${YELLOW}Choose the monitor to arrange: ${RC}" printf "%b\n" "${YELLOW}Choose the monitor to arrange: ${RC}"
i=1 i=1
for monitor in $monitor_array; do for monitor in $monitor_array; do
printf "%b\n" "$i. ${YELLOW}$monitor${RC}" printf "%b\n" "$i. ${GREEN}$monitor${RC}"
i=$((i + 1)) i=$((i + 1))
done done

View File

@ -16,7 +16,7 @@ set_primary_monitor() {
printf "%b\n" "${YELLOW}Choose a monitor to set as primary:${RC}" printf "%b\n" "${YELLOW}Choose a monitor to set as primary:${RC}"
i=1 i=1
for monitor in $monitor_array; do for monitor in $monitor_array; do
printf "%b\n" "$i. ${YELLOW}$monitor${RC}" printf "%b\n" "$i. ${GREEN}$monitor${RC}"
i=$((i + 1)) i=$((i + 1))
done done

View File

@ -1,4 +1,6 @@
<!-- THIS FILE IS GENERATED AUTOMATICALLY. EDIT .github/CONTRIBUTING.md -->\n\n# Contributing Guidelines for Linutil <!-- THIS FILE IS GENERATED AUTOMATICALLY. EDIT .github/CONTRIBUTING.md -->
# Contributing Guidelines for Linutil
Thank you for considering contributing to Linutil! We appreciate your effort in helping improve this project. To ensure that your contributions align with the goals and quality standards of Linutil, please follow these guidelines: Thank you for considering contributing to Linutil! We appreciate your effort in helping improve this project. To ensure that your contributions align with the goals and quality standards of Linutil, please follow these guidelines:
@ -16,6 +18,7 @@ cd linutil
``` ```
## 3. Make your changes ## 3. Make your changes
- **Edit the files you want to change**: Make your changes to the relevant files. - **Edit the files you want to change**: Make your changes to the relevant files.
- **Test your changes**: Run `cargo run` to test your modifications in a local environment and ensure everything works as expected. - **Test your changes**: Run `cargo run` to test your modifications in a local environment and ensure everything works as expected.
@ -60,6 +63,7 @@ cd linutil
## 11. Documentation ## 11. Documentation
- **Update the documentation**: If your change affects the functionality, please update the relevant documentation files to reflect this. - **Update the documentation**: If your change affects the functionality, please update the relevant documentation files to reflect this.
- **Automatic generation**: If you decide to add functionality through a new shell script, make sure to fill out all fields in `tab_data.toml` and run `cargo xtask docgen`.
## 12. License ## 12. License

View File

@ -1,5 +1,5 @@
use crate::{state::ListEntry, theme::Theme}; use crate::{state::ListEntry, theme::Theme};
use crossterm::event::{KeyCode, KeyEvent}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
use ego_tree::NodeId; use ego_tree::NodeId;
use linutil_core::Tab; use linutil_core::Tab;
use ratatui::{ use ratatui::{
@ -116,21 +116,27 @@ impl Filter {
pub fn handle_key(&mut self, event: &KeyEvent) -> SearchAction { pub fn handle_key(&mut self, event: &KeyEvent) -> SearchAction {
//Insert user input into the search bar //Insert user input into the search bar
match event.code { match event.code {
KeyCode::Char('c') if event.modifiers.contains(KeyModifiers::CONTROL) => {
return self.exit_search()
}
KeyCode::Char(c) => self.insert_char(c), KeyCode::Char(c) => self.insert_char(c),
KeyCode::Backspace => self.remove_previous(), KeyCode::Backspace => self.remove_previous(),
KeyCode::Delete => self.remove_next(), KeyCode::Delete => self.remove_next(),
KeyCode::Left => return self.cursor_left(), KeyCode::Left => return self.cursor_left(),
KeyCode::Right => return self.cursor_right(), KeyCode::Right => return self.cursor_right(),
KeyCode::Esc => {
self.input_position = 0;
self.search_input.clear();
return SearchAction::Exit;
}
KeyCode::Enter => return SearchAction::Exit, KeyCode::Enter => return SearchAction::Exit,
KeyCode::Esc => return self.exit_search(),
_ => return SearchAction::None, _ => return SearchAction::None,
}; };
SearchAction::Update SearchAction::Update
} }
fn exit_search(&mut self) -> SearchAction {
self.input_position = 0;
self.search_input.clear();
SearchAction::Exit
}
fn cursor_left(&mut self) -> SearchAction { fn cursor_left(&mut self) -> SearchAction {
self.input_position = self.input_position.saturating_sub(1); self.input_position = self.input_position.saturating_sub(1);
SearchAction::None SearchAction::None

View File

@ -119,7 +119,10 @@ impl AppState {
match self.focus { match self.focus {
Focus::Search => ( Focus::Search => (
"Search bar", "Search bar",
Box::new([Shortcut::new("Finish search", ["Enter"])]), Box::new([
Shortcut::new("Abort search", ["Esc", "CTRL-c"]),
Shortcut::new("Search", ["Enter"]),
]),
), ),
Focus::List => { Focus::List => {