mirror of
https://github.com/ethauvin/sdkman-for-fish.git
synced 2025-04-26 05:37:11 -07:00
parent
7c0ece3dfb
commit
4c15f15ced
8 changed files with 135 additions and 10 deletions
|
@ -47,10 +47,27 @@ Given(/^file ([a-zA-Z0-9\-_.\/]+) exists with content/) do |filename,content|
|
|||
File.write(filename, content)
|
||||
end
|
||||
|
||||
$fish_config_files = []
|
||||
def _remove_fish_configs # called in After hook
|
||||
$fish_config_files.each do |f|
|
||||
log "Removing #{f}"
|
||||
FileUtils.rm_f(f)
|
||||
end
|
||||
$fish_config_files = []
|
||||
end
|
||||
|
||||
And(/^fish config file ([a-zA-Z0-9\-_.\/]+) exists with content$/) do |filename,content|
|
||||
file = "#{ENV['HOME']}/.config/fish/conf.d/#{filename}"
|
||||
FileUtils.mkdir_p(File.dirname(file))
|
||||
File.write(file, content)
|
||||
$fish_config_files << file
|
||||
end
|
||||
|
||||
$config_file = "#{ENV['HOME']}/.sdkman/etc/config"
|
||||
$backup_config_file = nil
|
||||
def _restore_config # called in After hook
|
||||
unless $backup_config_file.nil?
|
||||
log "Restoring #{$config_file} from #{$backup_config_file.path}"
|
||||
FileUtils.mv($backup_config_file, $config_file)
|
||||
$backup_config_file = nil
|
||||
end
|
||||
|
@ -58,7 +75,8 @@ end
|
|||
|
||||
Given(/^SDKMAN! config sets ([a-z_]+) to (.*)$/) do |key,value|
|
||||
if $backup_config_file.nil?
|
||||
$backup_config_file = Tempfile.new('sdkman_config_backup')
|
||||
$backup_config_file = Tempfile.new('sdkman_config_backup_')
|
||||
log "Backing up #{$config_file} at #{$backup_config_file.path}"
|
||||
FileUtils.cp($config_file, $backup_config_file)
|
||||
end
|
||||
|
||||
|
@ -68,3 +86,37 @@ Given(/^SDKMAN! config sets ([a-z_]+) to (.*)$/) do |key,value|
|
|||
|
||||
File.write($config_file, new_config_string)
|
||||
end
|
||||
|
||||
# TODO: create shared helper for both config files
|
||||
#
|
||||
$fish_config = "#{ENV['HOME']}/.config/fish/config.fish"
|
||||
$backup_fish_config = nil
|
||||
def _restore_fish_config # called in After hook
|
||||
unless $backup_fish_config.nil?
|
||||
if $backup_fish_config == :none
|
||||
log "Deleting #{$fish_config}"
|
||||
FileUtils.rm($fish_config)
|
||||
else
|
||||
log "Restoring #{$fish_config} from #{$backup_fish_config.path}"
|
||||
FileUtils.mv($backup_fish_config, $fish_config)
|
||||
end
|
||||
$backup_fish_config = nil
|
||||
end
|
||||
end
|
||||
|
||||
And(/^fish config contains `([^`]+)`$/) do |line|
|
||||
if $backup_fish_config.nil?
|
||||
if File.exist?($fish_config)
|
||||
$backup_fish_config = Tempfile.new('fish_config_backup_')
|
||||
log "Backing up #{$fish_config} at #{$backup_fish_config.path}"
|
||||
FileUtils.cp($fish_config, $backup_fish_config)
|
||||
else
|
||||
$backup_fish_config = :none
|
||||
end
|
||||
end
|
||||
|
||||
config = File.exist?($fish_config) ? File.readlines($fish_config) : ''
|
||||
config << "\n\n# Added by sdkman-for-fish test\n#{line}"
|
||||
|
||||
File.write($fish_config, config.join("\n"))
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue