summaryrefslogtreecommitdiffstats
path: root/src/utils.rs
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-10-15 00:19:42 +0200
committerqkzk <qu3nt1n@gmail.com>2023-10-15 00:33:36 +0200
commit55e03cd91cfa18b1405b6919956f3c930f746fb1 (patch)
tree24bfed0be53c9a6be1ad1f5b1fa7724762d324a8 /src/utils.rs
parent4d6cdc51b5deb4f03dfe17dbfe17883fb1d8b934 (diff)
FIX: copy / move while existing file already exist use another name
Diffstat (limited to 'src/utils.rs')
-rw-r--r--src/utils.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 2305991..23d59cb 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -4,6 +4,7 @@ use std::path::Path;
use anyhow::{Context, Result};
use copypasta::{ClipboardContext, ClipboardProvider};
+use rand::Rng;
use sysinfo::{Disk, DiskExt};
use tuikit::term::Term;
use users::{get_current_uid, get_user_by_uid};
@@ -149,3 +150,16 @@ pub fn open_in_current_neovim(path_str: &str, nvim_server: &str) {
let command = &format!("<esc>:e {path_str}<cr><esc>:set number<cr><esc>:close<cr>");
let _ = nvim(nvim_server, command);
}
+
+/// Creates a random string.
+/// The string starts with `fm-` and contains 7 random alphanumeric characters.
+pub fn random_name() -> String {
+ let mut rand_str = String::with_capacity(14);
+ rand_str.push_str("fm-");
+ rand::thread_rng()
+ .sample_iter(&rand::distributions::Alphanumeric)
+ .take(7)
+ .for_each(|ch| rand_str.push(ch as char));
+ rand_str.push_str(".txt");
+ rand_str
+}