Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
neofetch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
neofetch
Commits
d7c99ecb
Commit
d7c99ecb
authored
Dec 25, 2016
by
Dylan Araps
Committed by
GitHub
Dec 25, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #562 from dylanaraps/pid
Term: Move pid handling to separate functions
parents
c0506dbc
918a684b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
39 deletions
+62
-39
neofetch
neofetch
+62
-39
No files found.
neofetch
View file @
d7c99ecb
...
@@ -1507,47 +1507,28 @@ get_term() {
...
@@ -1507,47 +1507,28 @@ get_term() {
# If function was run, stop here.
# If function was run, stop here.
(( "
$term_run
" == 1 )) && return
(( "
$term_run
" == 1 )) && return
# Check
$PPID
for terminal emulator.
# Workaround for macOS systems that
case "
$os
" in
# don't support the block below.
"
Mac OS X
")
case "
$TERM_PROGRAM
" in
# Workaround for macOS systems that
"
iTerm.app
") term="
iTerm2
" ;;
# don't support the block below.
"
Terminal.app
") term="
Apple Terminal
" ;;
case "
$TERM_PROGRAM
" in
"
Hyper
") term="
HyperTerm
" ;;
"
iTerm.app
") term="
iTerm2
" ;;
*) term="
${
TERM_PROGRAM
/\.app
}
" ;;
"
Terminal.app
") term="
Apple Terminal
" ;;
"
Hyper
") term="
HyperTerm
" ;;
*) term="
${
TERM_PROGRAM
/\.app
}
" ;;
esac
return
;;
"
Windows
")
parent="
$(
ps
-p
"
${
1
:-
$PPID
}
"
|
awk
'{printf $2}'
)
"
parent="
${
parent
/
'PPID'
}
"
name="
$(
ps
-p
"
$parent
"
|
awk
'{printf $8}'
)
"
name="
${
name
/
'COMMAND'
}
"
name="
${
name
/*\/
}
"
;;
"
Linux
")
parent="
$(
grep
-i
-F
"PPid:"
"/proc/
${
1
:-
$PPID
}
/status"
)
"
name="
$(
<
"/proc/
$(
trim
"
${
parent
/PPid
:
}
"
)
/comm"
)
"
;;
*)
parent="
$(
ps
-p
"
${
1
:-
$PPID
}
"
-o
ppid
=
)
"
name="
$(
ps
-p
"
$parent
"
-o
comm
=
)
"
;;
esac
esac
case "
${
name
//
}
" in
# Check
$PPID
for terminal emulator.
"
${
SHELL
/*\/
}
" | *"
sh
" | "
tmux
"* | "
screen
" | "
su
") get_term "
$parent
" ;;
while [[ -z "
$term
" ]]; do
"
login
"* | *"
Login
"* | "
init
" | "
(
init
)
") term="
$(
tty
)
" ;;
parent="
$(
get_ppid
"
$parent
"
)
"
"
ruby
" | "
1
" | "
systemd
" | "
sshd
"* | "
python
"* | "
USER
"*"
PID
"*) unset term ;;
name="
$(
get_process_name
"
$parent
"
)
"
"
gnome-terminal-
") term="
gnome-terminal
" ;;
*) term="
${
name
##*/
}
" ;;
case "
${
name
//
}
" in
esac
"
${
SHELL
/*\/
}
" | *"
sh
" | "
tmux
"* | "
screen
" | "
su
"*) ;;
"
login
"* | *"
Login
"* | "
init
" | "
(
init
)
") term="
$(
tty
)
" ;;
"
ruby
" | "
1
" | "
systemd
" | "
sshd
"* | "
python
"* | "
USER
"*"
PID
"*) break ;;
"
gnome-terminal-
") term="
gnome-terminal
" ;;
*) term="
${
name
##*/
}
" ;;
esac
done
# Log that the function was run.
# Log that the function was run.
term_run=1
term_run=1
...
@@ -3066,6 +3047,48 @@ convert_time() {
...
@@ -3066,6 +3047,48 @@ convert_time() {
printf
"%s"
"
$week_day
$day
$month
$year
$time
"
printf
"%s"
"
$week_day
$day
$month
$year
$time
"
}
}
get_ppid
()
{
# Get parent process ID of PID.
case
"
$os
"
in
"Windows"
)
ppid
=
"
$(
ps
-p
"
${
1
:-
$PPID
}
"
|
awk
'{printf $2}'
)
"
ppid
=
"
${
ppid
/
'PPID'
}
"
;;
"Linux"
)
ppid
=
"
$(
grep
-i
-F
"PPid:"
"/proc/
${
1
:-
$PPID
}
/status"
)
"
ppid
=
"
$(
trim
"
${
ppid
/PPid
:
}
"
)
"
;;
*
)
ppid
=
"
$(
ps
-p
"
${
1
:-
$PPID
}
"
-o
ppid
=
)
"
;;
esac
printf
"%s"
"
$ppid
"
}
get_process_name
()
{
# Get PID name.
case
"
$os
"
in
"Windows"
)
name
=
"
$(
ps
-p
"
${
1
:-
$PPID
}
"
|
awk
'{printf $8}'
)
"
name
=
"
${
name
/
'COMMAND'
}
"
name
=
"
${
name
/*\/
}
"
;;
"Linux"
)
name
=
"
$(
<
"/proc/
${
1
:-
$PPID
}
/comm"
)
"
;;
*
)
name
=
"
$(
ps
-p
"
${
1
:-
$PPID
}
"
-o
comm
=
)
"
;;
esac
printf
"%s"
"
$name
"
}
# FINISH UP
# FINISH UP
usage
()
{
printf
"%s"
"
\
usage
()
{
printf
"%s"
"
\
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment