From 1e58b357cd066bfbf595f204d6573ae0f6ba9a7a Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Sat, 23 Dec 2023 20:14:09 -0700 Subject: [PATCH] Update: localize time in bash history script --- .../src/prettify_bash_history.rs | 19 +++++++++++++++---- bin/rewritten_in_rust/src/rename_for_unix.rs | 4 ++-- vifm/vifmrc | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/bin/rewritten_in_rust/src/prettify_bash_history.rs b/bin/rewritten_in_rust/src/prettify_bash_history.rs index c12a75c..9be8cc6 100644 --- a/bin/rewritten_in_rust/src/prettify_bash_history.rs +++ b/bin/rewritten_in_rust/src/prettify_bash_history.rs @@ -1,4 +1,4 @@ -use chrono::NaiveDateTime; +use chrono::{NaiveDateTime, offset::{Local, TimeZone}}; use clap::{Parser, ValueEnum}; use regex::Regex; use std::fs::File; @@ -42,8 +42,11 @@ fn main() -> Result<(), Box> { for line in lines { if timestamp.is_match(&line) { - let time = NaiveDateTime::from_timestamp_opt(line[1..].parse()?, 0).unwrap(); - let fmttime = time.format("%a %b %e %T %Y").to_string(); + let unix_utc: i64 = line[1..].parse()?; + let time = NaiveDateTime::from_timestamp_opt(millis, 0).unwrap(); + let local_time = Local.from_utc_datetime(&time); + + let fmttime = local_time.format("%a %b %e %T %Y").to_string(); let start_line = starting_for_command_line(args.style); let time_line = format_time_line(&fmttime, args.style); @@ -96,6 +99,14 @@ fn format_command_line(line: &str, style: Style) -> String { match style { Style::Plain => format!(" {}", line), Style::Markdown => format!("{}", line), - Style::Html => format!("{}", line), + Style::Html => { + format!("{}", line + .replace("&", "&") + .replace("<", "<") + .replace(">", ">") + .replace("\"", """) + .replace("'", "'") + ) + }, } } diff --git a/bin/rewritten_in_rust/src/rename_for_unix.rs b/bin/rewritten_in_rust/src/rename_for_unix.rs index d3afede..52aa785 100644 --- a/bin/rewritten_in_rust/src/rename_for_unix.rs +++ b/bin/rewritten_in_rust/src/rename_for_unix.rs @@ -71,11 +71,11 @@ fn main() -> Try<()> { let og_base_name = og_full_name.file_name().unwrap().to_str().unwrap(); let new_base_name = new_full_name.file_name().unwrap().to_str().unwrap(); - if args.is_dry_run { + if args.is_dry_run && og_full_name != new_full_name { println!("{}\"{}\"{} -> {}{:?}{}", tc::Fg(tc::Red), og_base_name, tc::Fg(tc::Reset), tc::Fg(tc::Green), new_base_name, tc::Fg(tc::Reset)); - } else { + } else if !args.is_dry_run { if !args.is_silent { println!("{}", new_full_name.to_str().unwrap()); } diff --git a/vifm/vifmrc b/vifm/vifmrc index 530686c..1494521 100644 --- a/vifm/vifmrc +++ b/vifm/vifmrc @@ -40,7 +40,7 @@ nnoremap :!/usr/bin/env IS_VIFM_NEST='T' bash -l nnoremap :!/usr/bin/env IS_VIFM_NEST='T' bash -l " Rename file/dir under cursor to unix standards Ore[name] -nnoremap ore :exe 'goto "'.system("~/.configs_pointer/vifm/scripts/vifm_rename_and_move_file.sh ".expand('%c')).'"' +nnoremap ore :exe 'goto "'.system("~/.configs_pointer/bin/rename_for_unix ".expand('%c')).'"' " Logical conflict mappings " Navigate back from symlinks