Commit 9b349b9f authored by Leo's avatar Leo

Allow to disable auto-launch

 + When spawning a new terminal, it may be useful to be able to have oclaunch
 auto-launch disabled and start using the running terminal.
 + Refer to documentation (Auto-launch page) for details of the functionality
 (what it is, how to use it).
 + Need to improve status implementation.
parent 2fe6decb
......@@ -11,6 +11,7 @@ This version introduce major changes in the tmp and rc file.
#### Major
+ Allow to temporary disable oclaunch auto-run. Please refer to documentation for more.
+ Changed tmp file structure, the new one would allow to do more things: (See #6)
+ Restart edited command (reset number of launch).
+ Support multiple configuration file.
......
......@@ -279,6 +279,34 @@ let edit =
)
;;
(* Enable auto-launch *)
let enable_al =
basic
~summary:("Enable auto-launch, you may unset OC_DISABLE variable too.")
Spec.(
empty
+> shared_params
)
(fun _ () ->
Tmp_file.set_disable false
)
;;
(* Disable auto-launch *)
let disable_al =
basic
~summary:("Disable auto-launch, you may set OC_DISABLE variable too.")
Spec.(
empty
+> shared_params
)
(fun _ () ->
Tmp_file.set_disable true
)
;;
(* Import from older version *)
let import =
basic
......@@ -365,7 +393,7 @@ let run ~version ~build_info () =
[ ("run", default) ; ("licence", licence) ; ("add", add) ; ("edit", edit)
; ("list", list) ; ("cleanup", clean) ; ("delete", delete)
; ("state", state) ; ( "reset", reset) ; ( "reset-all", reset_all)
; ( "import", import ) ]
; ( "import", import ) ; ("enable", enable_al) ; ("disable", disable_al) ]
|> run ~version ~build_info
in
......
......@@ -101,6 +101,11 @@ let no_color =
|> (function "0" -> false | _ -> true)
)
;;
(* If this variable is set, auto run is disabled *)
(* TODO Allow to configure this in rc file *)
let disabled =
lazy (Sys.getenv "OC_DISABLE" |> Option.is_some)
;;
(* Default place to read settings, before version 0.3.x *)
let rc_file_old =
......
......@@ -37,6 +37,7 @@
(* Env variables *)
val home : string lazy_t
val editor : string lazy_t
val disabled : bool lazy_t
(* Settings *)
val verbosity : int ref
......
......@@ -63,11 +63,14 @@ let run_item ~rc num =
(* Execute each item (one after the other) in config file *)
let exec_each ~tmp =
Exec_cmd.what_next ~tmp
|> function
| Exec_cmd.Empty -> nothing_in_rc ()
| Finish -> no_cmd_found ()
| A cmd_to_exec -> Exec_cmd.execute cmd_to_exec
if not (Tmp_file.is_disabled ~tmp)
then
Exec_cmd.what_next ~tmp
|> function
| Exec_cmd.Empty -> nothing_in_rc ()
| Finish -> no_cmd_found ()
| A cmd_to_exec -> Exec_cmd.execute cmd_to_exec
else Messages.debug "Disabled"
;;
(* cmd_number is the number of the command the user wants
......
......@@ -38,7 +38,8 @@ open Core.Std;;
(* Module to display the current state of the program *)
(* Display current number *)
(* TODO Print whether auto-launch is set or not *)
(* Display current state *)
let print_current ~(rc:Rc.t) () =
Tmp_file.(init ()
|> (fun tmp -> get_accurate_log ~tmp ())
......
......@@ -39,7 +39,11 @@ open Core.Std;;
(* Type of the values *)
type rc_name = string [@@deriving bin_io];;
type rc_entry = { commands: (string * int) } [@@deriving bin_io];;
type tmp_file = { rc: (rc_name * (rc_entry list)) list; daemon: int } [@@deriving bin_io];;
type tmp_file = {
rc: (rc_name * (rc_entry list)) list;
disabled: bool;
daemon: int
} [@@deriving bin_io];;
type t = tmp_file;;
(* To use with Binable module *)
......@@ -82,8 +86,7 @@ let rec read () =
(* Function to create an empty tmp file *)
and create_tmp_file () =
(* An empty list, without rc, commands, launch... *)
{ daemon = 0; rc = [] }
{ daemon = 0; rc = []; disabled = false }
|> write
;;
......@@ -256,3 +259,18 @@ let reset_all () =
| Messages.No -> ()
;;
(* Check whether the program has been disabled (concerning automatic launch) *)
let is_disabled ~tmp =
sprintf "Tmp.disabled: %b" tmp.disabled
|> Messages.debug;
let r = tmp.disabled || (Lazy.force Const.disabled) in
sprintf "Tmp.disabled or OC_DISABLE set: %b" r
|> Messages.debug;
r
;;
(* Disable auto-launch *)
let set_disable target =
write { (init ()) with disabled = target }
;;
......@@ -36,7 +36,11 @@
type rc_name = string;;
type rc_entry = { commands: (string * int) };;
type tmp_file = { rc: (rc_name * (rc_entry list)) list; daemon: int };;
type tmp_file = {
rc: (rc_name * (rc_entry list)) list;
disabled: bool; (* Suspend launch of new entries *)
daemon: int
};;
type t = tmp_file;;
val write : t -> unit
......@@ -61,3 +65,7 @@ val get_accurate_log : ?entry_log:accurate_log -> tmp:t -> unit -> accurate_log_
val reset_cmd : rc:Rc.t -> int -> int -> unit
val reset2num : int -> unit
val reset_all : unit -> unit
(* Disable auto-launch *)
val is_disabled : tmp:t -> bool
val set_disable : bool -> unit
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment