Inline type annotations for Utils::Shell.
This commit is contained in:
parent
ff653571b1
commit
8fabc56a22
@ -1,38 +0,0 @@
|
||||
# typed: strict
|
||||
|
||||
module Utils::Shell
|
||||
include Kernel
|
||||
|
||||
sig{ params(path: String).returns(T.nilable(Symbol)) }
|
||||
def from_path(path)
|
||||
end
|
||||
|
||||
sig{ returns(T.nilable(Symbol)) }
|
||||
def preferred
|
||||
end
|
||||
|
||||
def parent
|
||||
end
|
||||
|
||||
def export_value(key, value, shell = preferred)
|
||||
end
|
||||
|
||||
sig{ returns(String) }
|
||||
def profile
|
||||
end
|
||||
|
||||
def set_variable_in_profile(variable, value)
|
||||
end
|
||||
|
||||
sig{ params(path: String).returns(T.nilable(String)) }
|
||||
def prepend_path_in_profile(path)
|
||||
end
|
||||
|
||||
sig{ params(str: String).returns(T.nilable(String)) }
|
||||
def csh_quote(str)
|
||||
end
|
||||
|
||||
sig{ params(str: String).returns(T.nilable(String)) }
|
||||
def sh_quote(str)
|
||||
end
|
||||
end
|
||||
@ -3,10 +3,14 @@
|
||||
|
||||
module Utils
|
||||
module Shell
|
||||
include Kernel
|
||||
extend T::Sig
|
||||
|
||||
module_function
|
||||
|
||||
# take a path and heuristically convert it
|
||||
# to a shell name, return nil if there's no match
|
||||
# Take a path and heuristically convert it to a shell name,
|
||||
# return `nil` if there's no match.
|
||||
sig { params(path: String).returns(T.nilable(Symbol)) }
|
||||
def from_path(path)
|
||||
# we only care about the basename
|
||||
shell_name = File.basename(path)
|
||||
@ -15,15 +19,18 @@ module Utils
|
||||
shell_name.to_sym if %w[bash csh fish ksh mksh sh tcsh zsh].include?(shell_name)
|
||||
end
|
||||
|
||||
sig { returns(T.nilable(Symbol)) }
|
||||
def preferred
|
||||
from_path(ENV.fetch("SHELL", ""))
|
||||
end
|
||||
|
||||
sig { returns(T.nilable(Symbol)) }
|
||||
def parent
|
||||
from_path(`ps -p #{Process.ppid} -o ucomm=`.strip)
|
||||
end
|
||||
|
||||
# quote values. quoting keys is overkill
|
||||
# Quote values. Quoting keys is overkill.
|
||||
sig { params(key: String, value: String, shell: T.nilable(Symbol)).returns(T.nilable(String)) }
|
||||
def export_value(key, value, shell = preferred)
|
||||
case shell
|
||||
when :bash, :ksh, :mksh, :sh, :zsh
|
||||
@ -38,7 +45,8 @@ module Utils
|
||||
end
|
||||
end
|
||||
|
||||
# return the shell profile file based on user's preferred shell
|
||||
# Return the shell profile file based on user's preferred shell.
|
||||
sig { returns(String) }
|
||||
def profile
|
||||
case preferred
|
||||
when :bash
|
||||
@ -51,6 +59,7 @@ module Utils
|
||||
SHELL_PROFILE_MAP.fetch(preferred, "~/.profile")
|
||||
end
|
||||
|
||||
sig { params(variable: String, value: String).returns(T.nilable(String)) }
|
||||
def set_variable_in_profile(variable, value)
|
||||
case preferred
|
||||
when :bash, :ksh, :sh, :zsh, nil
|
||||
@ -62,6 +71,7 @@ module Utils
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(path: String).returns(T.nilable(String)) }
|
||||
def prepend_path_in_profile(path)
|
||||
case preferred
|
||||
when :bash, :ksh, :mksh, :sh, :zsh, nil
|
||||
@ -86,6 +96,7 @@ module Utils
|
||||
|
||||
UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@~\n])}.freeze
|
||||
|
||||
sig { params(str: String).returns(String) }
|
||||
def csh_quote(str)
|
||||
# ruby's implementation of shell_escape
|
||||
str = str.to_s
|
||||
@ -99,6 +110,7 @@ module Utils
|
||||
str
|
||||
end
|
||||
|
||||
sig { params(str: String).returns(String) }
|
||||
def sh_quote(str)
|
||||
# ruby's implementation of shell_escape
|
||||
str = str.to_s
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user