Skip to content

Commit

Permalink
feat: added reading shells' profiles on Unix
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 02b843a49806e5f769ec4ff79f7bb505d10eb03d6135babd6edcf28a6393442b
  • Loading branch information
thindil committed Nov 29, 2023
1 parent a74c40a commit 4585a84
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/nish.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
## and stopping the shell and the main loop of the shell itself.

# Standard library imports
import std/[os, parseopt, strutils, tables, terminal, unicode]
import std/[os, osproc, parseopt, strutils, tables, terminal, unicode]
# External modules imports
import ansiparse, contracts, nancy, termstyle
import norm/sqlite
Expand Down Expand Up @@ -157,8 +157,9 @@ proc readUserInput*(inputString: var UserInput; oneTimeCommand: bool;
getCommandCompletion(prefix = prefix, completions = completions,
aliases = aliases, commands = commands, db = db)
elif spaceIndex > -1:
getCompletion(commandName = $inputString[0 .. spaceIndex - 1], prefix = prefix,
completions = completions, aliases = aliases, commands = commands, db = db)
getCompletion(commandName = $inputString[0 .. spaceIndex - 1],
prefix = prefix, completions = completions, aliases = aliases,
commands = commands, db = db)
if completions.len == 0:
continue
elif completions.len == 1:
Expand Down Expand Up @@ -422,6 +423,14 @@ proc main() {.sideEffect, raises: [], tags: [ReadIOEffect, WriteIOEffect,
commands: ref Table[string, CommandData] = newTable[string, CommandData]()
lastCommand: string = ""

# On Unix systems, load various users' configurations for shells
when not defined(windows):
let profiles: array[2, string] = ["/etc/profile", getHomeDir() & ".profile"]
for fileName in profiles:
logToFile(message = "Loading profile: " & fileName)
if fileExists(fileName) and execCmd(command = "sh '" & fileName & "'") != 0:
showError(message = "Can't load the shells configuration file '" & fileName & "'.")

# Check the command line parameters entered by the user. Available options
# are "-c [command]" to run only one command, "-h" or "--help" to show
# help about the shell's command line arguments, "-v" or "--version" to show
Expand Down

0 comments on commit 4585a84

Please sign in to comment.