-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d2ce9b
commit 1df718c
Showing
8 changed files
with
120 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "query.hpp" | ||
#include "util.hpp" | ||
#include "switch_fnv1a.hpp" | ||
|
||
using namespace Query; | ||
|
||
User::User() { | ||
uid_t uid = geteuid(); | ||
|
||
if (m_pPwd = getpwuid(uid), !m_pPwd) | ||
die("getpwent failed: {}\nCould not get user infos", errno); | ||
} | ||
|
||
std::string User::name() { | ||
return m_pPwd->pw_name; | ||
} | ||
|
||
std::string User::shell() { | ||
std::string shell = this->shell_path(); | ||
shell.erase(0, shell.find_last_of('/')); | ||
|
||
return shell; | ||
} | ||
|
||
std::string User::shell_path() { | ||
return m_pPwd->pw_shell; | ||
} | ||
|
||
std::string User::shell_version() { | ||
std::string shell = this->shell(); | ||
std::string ret = UNKNOWN; | ||
|
||
switch (fnv1a32::hash(shell)) { | ||
case "bash"_fnv1a32: | ||
case "osh"_fnv1a32: | ||
case "zsh"_fnv1a32: | ||
ret = shell_exec(fmt::format("{} -c \"printf %s \"${}_VERSION\"\"", shell, str_toupper(shell))); break; | ||
|
||
case "nu"_fnv1a32: | ||
ret = shell_exec("nu -c \"version | get version\""); break; | ||
|
||
default: | ||
ret = shell_exec(fmt::format("{} --version", shell)); | ||
ret.erase(0, ret.find(shell)); | ||
} | ||
|
||
strip(ret); | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters