Update: localize time in bash history script

This commit is contained in:
Akemi Izuko 2023-01-22 12:50:45 -07:00
parent 3736589a7c
commit 9ae7e5023a
No known key found for this signature in database
GPG key ID: 905D444F6A5E4BE4
3 changed files with 18 additions and 7 deletions

View file

@ -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<dyn std::error::Error>> {
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("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
.replace("'", "&apos;")
)
},
}
}

View file

@ -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());
}

View file

@ -40,7 +40,7 @@ nnoremap <C-l> :!/usr/bin/env IS_VIFM_NEST='T' bash -l<cr>
nnoremap <C-f> :!/usr/bin/env IS_VIFM_NEST='T' bash -l<cr>
" Rename file/dir under cursor to unix standards Ore[name]
nnoremap <space>ore :exe 'goto "'.system("~/.configs_pointer/vifm/scripts/vifm_rename_and_move_file.sh ".expand('%c')).'"'<cr>
nnoremap <space>ore :exe 'goto "'.system("~/.configs_pointer/bin/rename_for_unix ".expand('%c')).'"'<cr>
" Logical conflict mappings
" Navigate back from symlinks