Update: localize time in bash history script

This commit is contained in:
Akemi Izuko 2023-12-23 20:14:09 -07:00
parent f3121d12e1
commit 1e58b357cd
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC
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 clap::{Parser, ValueEnum};
use regex::Regex; use regex::Regex;
use std::fs::File; use std::fs::File;
@ -42,8 +42,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for line in lines { for line in lines {
if timestamp.is_match(&line) { if timestamp.is_match(&line) {
let time = NaiveDateTime::from_timestamp_opt(line[1..].parse()?, 0).unwrap(); let unix_utc: i64 = line[1..].parse()?;
let fmttime = time.format("%a %b %e %T %Y").to_string(); 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 start_line = starting_for_command_line(args.style);
let time_line = format_time_line(&fmttime, 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 { match style {
Style::Plain => format!(" {}", line), Style::Plain => format!(" {}", line),
Style::Markdown => 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 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(); 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!("{}\"{}\"{} -> {}{:?}{}", println!("{}\"{}\"{} -> {}{:?}{}",
tc::Fg(tc::Red), og_base_name, tc::Fg(tc::Reset), tc::Fg(tc::Red), og_base_name, tc::Fg(tc::Reset),
tc::Fg(tc::Green), new_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 { if !args.is_silent {
println!("{}", new_full_name.to_str().unwrap()); 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> nnoremap <C-f> :!/usr/bin/env IS_VIFM_NEST='T' bash -l<cr>
" Rename file/dir under cursor to unix standards Ore[name] " 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 " Logical conflict mappings
" Navigate back from symlinks " Navigate back from symlinks