From 4c584522a28f2a842affad4eb6bfb1c6e5a9e1bb Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sat, 23 Dec 2023 20:14:05 -0700 Subject: [PATCH] Rewrite: move sway_tree.rs --- bin/prettify_bash_history.awk | 9 -------- bin/rewritten_in_rust/Cargo.toml | 4 ++++ bin/{ => rewritten_in_rust/src}/sway_tree.rs | 0 post_install.sh | 24 ++++++++++++++------ 4 files changed, 21 insertions(+), 16 deletions(-) delete mode 100755 bin/prettify_bash_history.awk rename bin/{ => rewritten_in_rust/src}/sway_tree.rs (100%) diff --git a/bin/prettify_bash_history.awk b/bin/prettify_bash_history.awk deleted file mode 100755 index aba8ad1..0000000 --- a/bin/prettify_bash_history.awk +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env -S awk -f -# Translate the unix-timestamps in bash history to dates. Requires gnu `date` -{ - if ($0 ~ /^#[0-9]+$/) - system("date -d @" substr($0, 2)); - else - print " "$0 -} - diff --git a/bin/rewritten_in_rust/Cargo.toml b/bin/rewritten_in_rust/Cargo.toml index 03f4e8b..2426d73 100644 --- a/bin/rewritten_in_rust/Cargo.toml +++ b/bin/rewritten_in_rust/Cargo.toml @@ -10,6 +10,10 @@ authors = ["Akemi Izuko"] name = "prettify_bash_history" path = "src/prettify_bash_history.rs" +[[bin]] +name = "sway_tree" +path = "src/sway_tree.rs" + [dependencies] clap = { version = "4", features = ["derive"] } chrono = "0.4" diff --git a/bin/sway_tree.rs b/bin/rewritten_in_rust/src/sway_tree.rs similarity index 100% rename from bin/sway_tree.rs rename to bin/rewritten_in_rust/src/sway_tree.rs diff --git a/post_install.sh b/post_install.sh index 3053340..8906dbc 100755 --- a/post_install.sh +++ b/post_install.sh @@ -417,9 +417,11 @@ russy_checks() { check_for_russy_bins() { local -i return_code=0 - local -a bin_names - bin_names=($(awk '/name =/ { split($0, a, "\""); print a[2] }' ~/.configs_pointer/bin/rewritten_in_rust/Cargo.toml)) + + while IFS='' read -r line; do + bin_names+=("$line") + done < <(awk '/name =/ { split($0, a, "\""); print a[2] }' ~/.configs_pointer/bin/rewritten_in_rust/Cargo.toml) if [[ $? -eq 0 ]]; then for (( i = 1; i < "${#bin_names[@]}"; i++ )); do @@ -443,15 +445,22 @@ check_for_russy_bins() { russy_build() { if command -v cargo &>/dev/null; then if cargo build --release --manifest-path="$HOME/.configs_pointer/bin/rewritten_in_rust/Cargo.toml"; then + local -a bin_names + + while IFS='' read -r line; do + bin_names+=("$line") + done < <(awk '/name =/ { split($0, a, "\""); print a[2] }' ~/.configs_pointer/bin/rewritten_in_rust/Cargo.toml) + local name - for exe in $(fd -d1 -tx . ~/.configs_pointer/bin/rewritten_in_rust/target/release); do - name="$(basename "$exe")" + for (( i = 1; i < "${#bin_names[@]}"; i++ )); do + name="$(basename "${bin_names[i]}")" ( cd ~/.configs_pointer/bin || return 1 if ! [[ -e "$name" ]]; then ln -s "./rewritten_in_rust/target/release/$name" "./$name" + echo "$name" >> ~/.configs_pointer/bin/.gitignore elif ! [[ -L "$name" ]]; then printf 'ERR: Failed to link rust binary \`%s\`\n' "$name" printf '\tRemove the conflicting file\n' @@ -470,8 +479,11 @@ russy_build() { fi } +if [[ "$1" == 'build' ]]; then + russy_build || exit 1 +fi -if [[ "$1" == 'status' && "$(uname -s)" == 'Linux' ]]; then +if [[ "$(uname -s)" == 'Linux' ]] && [[ "$1" == 'status' || "$1" == 'build' ]]; then configs_pointer_is_setup || exit 1 swayland_checks @@ -485,8 +497,6 @@ if [[ "$1" == 'status' && "$(uname -s)" == 'Linux' ]]; then git_checks ssh_checks russy_checks -elif [[ "$1" == 'build' ]]; then - russy_build else print_help fi