Skip to content
This repository has been archived by the owner on Apr 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #9 from Rory-Finnegan/fish-shell
Browse files Browse the repository at this point in the history
Initial attempt at supporting fish shell.
  • Loading branch information
Rory Finnegan authored and Rory Finnegan committed Nov 30, 2015
2 parents ea7b28b + d95cea9 commit 5349175
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/activate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ function activate(config::Config; dir::AbstractString="", name::AbstractString="
init(config)

pg = PlaygroundConfig(config, dir, name)
set_envs(pg)

prompt = config.default_prompt

Expand All @@ -12,24 +11,28 @@ function activate(config::Config; dir::AbstractString="", name::AbstractString="
found = get_playground_name(config, pg.root_path)
if found != ""
prompt = replace(prompt, "playground", found)
pg.name = found
end
end

run_shell(prompt)
set_envs(pg)
run_shell(pg, prompt)
end


@windows_only begin
function run_shell(prompt)
function run_shell(config, prompt)
run(`cmd /K prompt $(prompt)`)
end
end


@unix_only begin
function run_shell(prompt)
function run_shell(config, prompt)
ENV["PS1"] = prompt
if haskey(ENV, "SHELL")
if haskey(ENV, "SHELL") && contains(ENV["SHELL"], "fish")
run(`$(ENV["SHELL"]) -i`)
elseif haskey(ENV, "SHELL")
# Try and setup the new shell as close to the user's default shell as possible.
usr_rc = joinpath(homedir(), "." * basename(ENV["SHELL"]) * "rc")
pg_rc = joinpath(dirname(ENV["JULIA_PKGDIR"]), basename(ENV["SHELL"]) * "rc")
Expand Down
11 changes: 11 additions & 0 deletions src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config
dir::DirectoryStructure
default_playground_path::AbstractString
default_prompt::AbstractString
default_shell::AbstractString
default_git_address::AbstractString
default_git_revision::AbstractString
isolated_shell_history::Bool
Expand All @@ -34,6 +35,7 @@ type Config
DirectoryStructure(kwargs["root"]),
abspath(kwargs["default_playground_path"]),
kwargs["default_prompt"],
haskey(kwargs, "default_shell") ? kwargs["default_shell"] : "",
kwargs["default_git_address"],
kwargs["default_git_revision"],
kwargs["isolated_shell_history"],
Expand All @@ -44,22 +46,26 @@ end


type PlaygroundConfig
name::AbstractString
root_path::AbstractString
log_path::AbstractString
bin_path::AbstractString
pkg_path::AbstractString
julia_path::AbstractString
default_shell::AbstractString
isolated_shell_history::Bool
isolated_julia_history::Bool

function PlaygroundConfig(config::Config, dir::AbstractString, name)
root_path = get_playground_dir(config, dir, name)
new(
name,
root_path,
joinpath(root_path, "log"),
joinpath(root_path, "bin"),
joinpath(root_path, "packages"),
joinpath(root_path, "bin", "julia"),
config.default_shell,
config.isolated_shell_history,
config.isolated_julia_history
)
Expand Down Expand Up @@ -104,8 +110,13 @@ end

function set_envs(pg::PlaygroundConfig)
ENV["PATH"] = "$(pg.bin_path):" * ENV["PATH"]
ENV["PLAYGROUND_ENV"] = pg.name == "" ? basename(pg.root_path) : pg.name
ENV["JULIA_PKGDIR"] = pg.pkg_path

if pg.default_shell != ""
ENV["SHELL"] = pg.default_shell
end

if pg.isolated_julia_history
ENV["JULIA_HISTORY"] = joinpath(pg.root_path, ".julia_history")
end
Expand Down
6 changes: 5 additions & 1 deletion src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ default_playground_path: .playground
# Default shell prompt when you activate a playground.
default_prompt: \"$(escape_string(DEFAULT_PROMPT))\"
# Uncomment below to change the default shell. Otherwise the SHELL
# Environment variable will be used.
# default_shell: /usr/local/bin/fish
# Default git settings when using install build
default_git_address: \"https://github.com/JuliaLang/julia.git\"
default_git_revision: master
# Allows you to isolate shell and julia history to each playground.
isolated_shell_history: true
isolated_julia_history: true
"""
"""

0 comments on commit 5349175

Please sign in to comment.