@@ -8,6 +8,7 @@ use press_btn_continue;
8
8
use serde_derive:: Deserialize ;
9
9
use sqlite;
10
10
use std:: {
11
+ include_str,
11
12
collections:: HashMap ,
12
13
env:: current_exe,
13
14
env:: { current_dir, var} ,
@@ -44,14 +45,14 @@ impl Env {
44
45
Ok ( loc) => PathBuf :: from ( & loc) ,
45
46
Err ( _) => {
46
47
home_dir. push ( ".config" ) ;
47
- home_dir. push ( "hop " ) ;
48
+ home_dir. push ( "bunnyhop " ) ;
48
49
home_dir
49
50
}
50
51
} ;
51
52
let mut hop_config_file = PathBuf :: from ( & config_dir) ;
52
53
match var ( "HOP_CONFIG_FILE_NAME" ) {
53
54
Ok ( name) => hop_config_file. push ( name) ,
54
- Err ( _) => hop_config_file. push ( "hop .toml" ) ,
55
+ Err ( _) => hop_config_file. push ( "bunnyhop .toml" ) ,
55
56
} ;
56
57
let mut database_dir = match var ( "HOP_DATABASE_DIRECTORY" ) {
57
58
Ok ( loc) => PathBuf :: from ( & loc) ,
@@ -70,7 +71,7 @@ impl Env {
70
71
} ;
71
72
match var ( "HOP_DATABASE_FILE_NAME" ) {
72
73
Ok ( name) => database_dir. push ( name) ,
73
- Err ( _) => database_dir. push ( "hop.sqlite " ) ,
74
+ Err ( _) => database_dir. push ( "bunnyhop.db " ) ,
74
75
} ;
75
76
76
77
Env {
@@ -79,8 +80,7 @@ impl Env {
79
80
}
80
81
}
81
82
}
82
- // Suppressing assignment warnings as functionality that uses `config` will be added in the future.
83
- #[ allow( dead_code) ]
83
+
84
84
pub struct Hopper {
85
85
pub config : Config ,
86
86
pub env : Env ,
@@ -99,8 +99,9 @@ impl Hopper {
99
99
. expect ( "[error] Unable to create config directory." ) ;
100
100
let mut new_conf =
101
101
fs:: File :: create ( & env. config_file ) . expect ( "[error] Unable to create config file." ) ;
102
+ static DEFAULT_CONFIGS : & str = include_str ! ( "defaults/defaults.toml" ) ;
102
103
new_conf
103
- . write_all ( b"[settings] \n default_editor= \" nvim \" \n max_history=0 \n ls_display_block=0" )
104
+ . write_all ( DEFAULT_CONFIGS . as_bytes ( ) )
104
105
. expect ( "[error] Unable to generate default config file." ) ;
105
106
} ;
106
107
let toml_str: String = fs:: read_to_string ( env. config_file . clone ( ) ) . unwrap ( ) ;
@@ -128,7 +129,7 @@ impl Hopper {
128
129
} )
129
130
}
130
131
131
- pub fn add_hop < T : AsRef < Path > > ( & mut self , path : T , name : & str ) -> anyhow:: Result < ( ) > {
132
+ fn add_hop < T : AsRef < Path > > ( & mut self , path : T , name : & str ) -> anyhow:: Result < ( ) > {
132
133
let query = format ! (
133
134
"INSERT OR REPLACE INTO named_hops (name, location) VALUES (\" {}\" , \" {}\" )" ,
134
135
name,
@@ -139,7 +140,7 @@ impl Hopper {
139
140
Ok ( ( ) )
140
141
}
141
142
142
- pub fn remove_hop ( & mut self , bunny : args:: Rabbit ) -> anyhow:: Result < ( ) > {
143
+ fn remove_hop ( & mut self , bunny : args:: Rabbit ) -> anyhow:: Result < ( ) > {
143
144
let output_pair = match bunny {
144
145
args:: Rabbit :: RequestName ( name) => {
145
146
Some ( ( format ! ( "name=\" {}\" " , name) , format ! ( "shortcut: {}" , name) ) )
@@ -182,7 +183,7 @@ impl Hopper {
182
183
}
183
184
}
184
185
185
- pub fn use_hop ( & mut self , shortcut_name : String ) -> anyhow:: Result < ( ) > {
186
+ fn use_hop ( & mut self , shortcut_name : String ) -> anyhow:: Result < ( ) > {
186
187
let query = format ! (
187
188
"SELECT location FROM named_hops WHERE name=\" {}\" " ,
188
189
& shortcut_name
@@ -221,7 +222,7 @@ impl Hopper {
221
222
}
222
223
}
223
224
224
- pub fn just_do_it ( & mut self , bunny : Rabbit ) -> anyhow:: Result < ( ) > {
225
+ fn just_do_it ( & mut self , bunny : Rabbit ) -> anyhow:: Result < ( ) > {
225
226
match bunny {
226
227
Rabbit :: File ( hop_name, hop_path) => self . add_hop ( hop_path, & hop_name) ,
227
228
Rabbit :: Dir ( hop_name, hop_path) => self . add_hop ( hop_path, & hop_name) ,
@@ -230,7 +231,7 @@ impl Hopper {
230
231
}
231
232
}
232
233
233
- pub fn log_history ( & self , location : String , name : String ) -> anyhow:: Result < ( ) > {
234
+ fn log_history ( & self , location : String , name : String ) -> anyhow:: Result < ( ) > {
234
235
if self . config . settings . max_history > 0 {
235
236
let query = format ! (
236
237
"INSERT INTO history (time, name, location) VALUES ({}, \" {}\" , \" {}\" ) " ,
@@ -251,7 +252,7 @@ impl Hopper {
251
252
Ok ( ( ) )
252
253
}
253
254
254
- pub fn check_dir ( & self , name : & str ) -> Option < ( PathBuf , String ) > {
255
+ fn check_dir ( & self , name : & str ) -> Option < ( PathBuf , String ) > {
255
256
read_dir ( current_dir ( ) . unwrap ( ) )
256
257
. expect ( "[error] Unable to search contents of current directory." )
257
258
. filter ( |f| f. is_ok ( ) )
@@ -269,7 +270,7 @@ impl Hopper {
269
270
. find ( |( _, path_end) | path_end == name)
270
271
}
271
272
272
- pub fn list_hops ( & self ) -> anyhow:: Result < ( ) > {
273
+ fn list_hops ( & self ) -> anyhow:: Result < ( ) > {
273
274
let query = format ! ( "SELECT name, location FROM named_hops" ) ;
274
275
let mut query_result = self . db . prepare ( & query) ?;
275
276
let mut hops: Vec < ( String , String ) > = Vec :: new ( ) ;
@@ -312,43 +313,14 @@ impl Hopper {
312
313
Ok ( ( ) )
313
314
}
314
315
315
- pub fn hop_names ( & self ) -> anyhow:: Result < Vec < String > > {
316
- let query = format ! ( "SELECT name FROM named_hops" ) ;
317
- let mut query_result = self . db . prepare ( & query) ?;
318
- let mut hops: Vec < String > = Vec :: new ( ) ;
319
- while let Ok ( sqlite:: State :: Row ) = query_result. next ( ) {
320
- let name = query_result. read :: < String , _ > ( "name" ) ?;
321
- hops. push ( name) ;
322
- }
323
- Ok ( hops)
324
- }
325
-
326
- pub fn brb < T : AsRef < Path > > ( & mut self , path : T ) -> anyhow:: Result < ( ) > {
316
+ fn brb < T : AsRef < Path > > ( & mut self , path : T ) -> anyhow:: Result < ( ) > {
327
317
self . add_hop ( path. as_ref ( ) , "back" ) ?;
328
318
Ok ( ( ) )
329
319
}
330
320
331
- pub fn print_help ( ) -> anyhow:: Result < ( ) > {
321
+ fn print_help ( ) -> anyhow:: Result < ( ) > {
332
322
println ! (
333
- r#"
334
- {} {} {}
335
- 1) First argument is required.
336
- 2) Second argument is optional.
337
-
338
- Valid first argument commands are:
339
- 1) {}: command to add a shortcut to the current directory.
340
- If a second argument is given, that argument is the name that will
341
- be used to refer to the shortcut for future use.
342
- If no second argument is given, the high level name will be used.
343
- 2) {} or {}: command to list the current shortcuts and their names.
344
- 3) {} or {}: both commands to show current hop version info.
345
- 4) {}: command to create a temporary shortcut to the current directory
346
- that can be jumped back to using the {} {} command.
347
- 5) {} or {}: command to remove the shortcut specified by {}.
348
- 6) {}: Any other first arguments given will be checked to see if it
349
- represents a valid directory/file to hop to. This input can be a named
350
- shortcut, a file/directory in the current directory, or a file/directory
351
- from previous {} commands."# ,
323
+ include!( "defaults/help.txt" ) ,
352
324
"hp" . bold( ) ,
353
325
"arg1" . italic( ) . dimmed( ) ,
354
326
"arg2" . italic( ) . dimmed( ) ,
@@ -369,7 +341,7 @@ Valid first argument commands are:
369
341
Ok ( ( ) )
370
342
}
371
343
372
- pub fn runner ( & self , cmd : String ) -> anyhow:: Result < ( ) > {
344
+ fn runner ( & self , cmd : String ) -> anyhow:: Result < ( ) > {
373
345
let bunnyhop_exe = current_exe ( )
374
346
. expect ( "[error] Unable to extract current bunnyhop executable name." )
375
347
. into_os_string ( )
0 commit comments