mirror of https://github.com/tildeclub/welcome.git
parent
eabb3c33c9
commit
356f8254c0
20
welcome.rb
20
welcome.rb
|
@ -52,6 +52,7 @@ puts
|
||||||
|
|
||||||
shells = File.readlines("/etc/shells")
|
shells = File.readlines("/etc/shells")
|
||||||
.select { |line| !line.start_with?("#") }
|
.select { |line| !line.start_with?("#") }
|
||||||
|
.select { |line| File.basename(line).match?(/^(sh|bash|zsh|fish|csh|tcsh|ksh|mksh|dash|xonsh|powershell|elvish|rksh|rmksh|hx)$/) }
|
||||||
.map(&:chomp)
|
.map(&:chomp)
|
||||||
.map { |line| [File.basename(line), line] }
|
.map { |line| [File.basename(line), line] }
|
||||||
.to_h
|
.to_h
|
||||||
|
@ -62,8 +63,19 @@ puts " great, you've picked #{shell}!"
|
||||||
puts " in order to change your shell, you'll have to enter your password again"
|
puts " in order to change your shell, you'll have to enter your password again"
|
||||||
|
|
||||||
success = false
|
success = false
|
||||||
until success do
|
retries = 3
|
||||||
|
until success || retries == 0 do
|
||||||
success = system "chsh -s #{shell}"
|
success = system "chsh -s #{shell}"
|
||||||
|
unless success
|
||||||
|
retries -= 1
|
||||||
|
puts " Error: Failed to change the shell. Please try again. (#{retries} retries left)"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if success
|
||||||
|
puts " Your default shell has been successfully changed to #{shell}."
|
||||||
|
else
|
||||||
|
puts " Failed to change the shell after multiple attempts. Please contact support."
|
||||||
end
|
end
|
||||||
|
|
||||||
# default text editor
|
# default text editor
|
||||||
|
@ -87,7 +99,7 @@ puts " great, you've picked #{editors}!"
|
||||||
|
|
||||||
success = false
|
success = false
|
||||||
until success do
|
until success do
|
||||||
success = system "echo 'export EDITOR=#{editors}' >> #{Dir.home}/.profile"
|
success = system "echo 'export EDITOR=#{editors}' >> #{Dir.home}/.bash_profile"
|
||||||
end
|
end
|
||||||
|
|
||||||
# byobu or not
|
# byobu or not
|
||||||
|
@ -122,8 +134,8 @@ if File.basename(shell) == "zsh"
|
||||||
open("#{Dir.home}/.zshrc", "a") { |f| f.puts "export TZ='#{tz}'" }
|
open("#{Dir.home}/.zshrc", "a") { |f| f.puts "export TZ='#{tz}'" }
|
||||||
puts " Timezone set in your .zshrc file for ZSH."
|
puts " Timezone set in your .zshrc file for ZSH."
|
||||||
else
|
else
|
||||||
open("#{Dir.home}/.profile", "a") { |f| f.puts "export TZ='#{tz}'" }
|
open("#{Dir.home}/.bash_profile", "a") { |f| f.puts "export TZ='#{tz}'" }
|
||||||
puts " Timezone set in your .profile file."
|
puts " Timezone set in your .bash_profile file."
|
||||||
end
|
end
|
||||||
puts " It might not take effect until you log out and back in."
|
puts " It might not take effect until you log out and back in."
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue